mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 22:03:40 +00:00
don't crash when calling EnumNameXXX on sparse enum (#4982)
Make an out-of-bounds check for enum values before using them to index the names array. For consistency with non-sparse enums an empty string is returned. Fixes #4821
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
a4f9d1bfcc
commit
99fe1dc80f
@@ -1285,6 +1285,14 @@ void EnumStringsTest() {
|
||||
true);
|
||||
}
|
||||
|
||||
void EnumNamesTest() {
|
||||
TEST_EQ_STR("Red", EnumNameColor(Color_Red));
|
||||
TEST_EQ_STR("Green", EnumNameColor(Color_Green));
|
||||
TEST_EQ_STR("Blue", EnumNameColor(Color_Blue));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(-1)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(1000)));
|
||||
}
|
||||
|
||||
void IntegerOutOfRangeTest() {
|
||||
TestError("table T { F:byte; } root_type T; { F:128 }",
|
||||
"constant does not fit");
|
||||
@@ -2058,6 +2066,7 @@ int FlatBufferTests() {
|
||||
ErrorTest();
|
||||
ValueTest();
|
||||
EnumStringsTest();
|
||||
EnumNamesTest();
|
||||
IntegerOutOfRangeTest();
|
||||
IntegerBoundaryTest();
|
||||
UnicodeTest();
|
||||
|
||||
Reference in New Issue
Block a user