From d779308b3e48124dae91896700bf3cc12b5251e3 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 10 Feb 2016 11:25:31 -0800 Subject: [PATCH] Fixed enum declaration values being parsed as int. This caused values in the uint range to be made negative values. Change-Id: Ia4284747f48508b589c034ff3aae0d141e96eb3c Tested: on Linux. --- src/idl_parser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index a133b75cb..622a1f61b 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1082,7 +1082,7 @@ CheckedError Parser::ParseEnum(bool is_union, EnumDef **dest) { } if (Is('=')) { NEXT(); - ev.value = atoi(attribute_.c_str()); + ev.value = StringToInt(attribute_.c_str()); EXPECT(kTokenIntegerConstant); if (!opts.proto_mode && prevsize && enum_def.vals.vec[prevsize - 1]->value >= ev.value) @@ -1146,7 +1146,7 @@ CheckedError Parser::CheckClash(std::vector &fields, } return NoError(); } - + static bool compareFieldDefs(const FieldDef *a, const FieldDef *b) { auto a_id = atoi(a->attributes.Lookup("id")->constant.c_str()); auto b_id = atoi(b->attributes.Lookup("id")->constant.c_str()); @@ -1307,7 +1307,7 @@ CheckedError Parser::ParseProtoDecl() { if (Is(';')) NEXT(); // Protobuf allows them to be specified in any order, so sort afterwards. auto &v = enum_def->vals.vec; - std::sort(v.begin(), v.end(), compareEnumVals); + std::sort(v.begin(), v.end(), compareEnumVals); // Temp: remove any duplicates, as .fbs files can't handle them. for (auto it = v.begin(); it != v.end(); ) {