From c2cf03536e74ada0073d371b962284220279a709 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Sat, 20 Apr 2024 22:44:44 -0700 Subject: [PATCH] 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 --- folly/Conv.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/folly/Conv.cpp b/folly/Conv.cpp index b953dd8c607..0ec8e5372d5 100644 --- a/folly/Conv.cpp +++ b/folly/Conv.cpp @@ -18,6 +18,8 @@ #include +#include + namespace folly { namespace detail { @@ -767,8 +769,9 @@ ConversionError makeConversionError(ConversionCode code, StringPiece input) { static_assert( std::is_unsigned::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(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}; }