Skip to content

Commit c2cf035

Browse files
yfeldblumfacebook-github-bot
authored andcommitted
let makeConversionError always check the ConversionCode
Summary: Just an extra check. Could potentially help disprove one plausible cause of a crash. Differential Revision: D56368867 fbshipit-source-id: 8d641862e271f22c64f7f747064ef9327bc97db1
1 parent 0540a52 commit c2cf035

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

folly/Conv.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <array>
2020

21+
#include <folly/lang/SafeAssert.h>
22+
2123
namespace folly {
2224
namespace detail {
2325

@@ -767,8 +769,9 @@ ConversionError makeConversionError(ConversionCode code, StringPiece input) {
767769
static_assert(
768770
std::is_unsigned<std::underlying_type<ConversionCode>::type>::value,
769771
"ConversionCode should be unsigned");
770-
assert((std::size_t)code < kErrorStrings.size());
771-
const ErrorString& err = kErrorStrings[(std::size_t)code];
772+
auto index = static_cast<std::size_t>(code);
773+
FOLLY_SAFE_CHECK(index < kErrorStrings.size(), "code=", uint64_t(index));
774+
const ErrorString& err = kErrorStrings[index];
772775
if (code == ConversionCode::EMPTY_INPUT_STRING && input.empty()) {
773776
return {err.string, code};
774777
}

0 commit comments

Comments
 (0)