Skip to content

Commit

Permalink
let makeConversionError always check the ConversionCode
Browse files Browse the repository at this point in the history
Summary: Just an extra check. Could potentially help disprove one plausible cause of a crash.

Differential Revision: D56368867

fbshipit-source-id: 8d641862e271f22c64f7f747064ef9327bc97db1
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Apr 21, 2024
1 parent 0540a52 commit c2cf035
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions folly/Conv.cpp
Expand Up @@ -18,6 +18,8 @@

#include <array>

#include <folly/lang/SafeAssert.h>

namespace folly {
namespace detail {

Expand Down Expand Up @@ -767,8 +769,9 @@ ConversionError makeConversionError(ConversionCode code, StringPiece input) {
static_assert(
std::is_unsigned<std::underlying_type<ConversionCode>::type>::value,
"ConversionCode should be unsigned");
assert((std::size_t)code < kErrorStrings.size());
const ErrorString& err = kErrorStrings[(std::size_t)code];
auto index = static_cast<std::size_t>(code);
FOLLY_SAFE_CHECK(index < kErrorStrings.size(), "code=", uint64_t(index));
const ErrorString& err = kErrorStrings[index];
if (code == ConversionCode::EMPTY_INPUT_STRING && input.empty()) {
return {err.string, code};
}
Expand Down

0 comments on commit c2cf035

Please sign in to comment.