diff options
author | Frank Benkstein <frank@benkstein.net> | 2018-10-08 23:37:35 +0200 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2018-10-08 14:37:35 -0700 |
commit | 99fe1dc80f192ed5c01c90ac086e14694d4250fb (patch) | |
tree | d933299d74535491f1d8405e1ac029ce684d0335 /samples | |
parent | a4f9d1bfcc6f159a921776abf54f4a09ce802be1 (diff) | |
download | flatbuffers-99fe1dc80f192ed5c01c90ac086e14694d4250fb.tar.gz flatbuffers-99fe1dc80f192ed5c01c90ac086e14694d4250fb.tar.bz2 flatbuffers-99fe1dc80f192ed5c01c90ac086e14694d4250fb.zip |
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
Diffstat (limited to 'samples')
-rw-r--r-- | samples/monster_generated.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/samples/monster_generated.h b/samples/monster_generated.h index 07fbd3a4..4fbbeccc 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -55,6 +55,7 @@ inline const char * const *EnumNamesColor() { } inline const char *EnumNameColor(Color e) { + if (e < Color_Red || e > Color_Blue) return ""; const size_t index = static_cast<int>(e); return EnumNamesColor()[index]; } @@ -84,6 +85,7 @@ inline const char * const *EnumNamesEquipment() { } inline const char *EnumNameEquipment(Equipment e) { + if (e < Equipment_NONE || e > Equipment_Weapon) return ""; const size_t index = static_cast<int>(e); return EnumNamesEquipment()[index]; } |