mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 19:21:10 +00:00
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.
This commit is contained in:
@@ -1082,7 +1082,7 @@ CheckedError Parser::ParseEnum(bool is_union, EnumDef **dest) {
|
|||||||
}
|
}
|
||||||
if (Is('=')) {
|
if (Is('=')) {
|
||||||
NEXT();
|
NEXT();
|
||||||
ev.value = atoi(attribute_.c_str());
|
ev.value = StringToInt(attribute_.c_str());
|
||||||
EXPECT(kTokenIntegerConstant);
|
EXPECT(kTokenIntegerConstant);
|
||||||
if (!opts.proto_mode && prevsize &&
|
if (!opts.proto_mode && prevsize &&
|
||||||
enum_def.vals.vec[prevsize - 1]->value >= ev.value)
|
enum_def.vals.vec[prevsize - 1]->value >= ev.value)
|
||||||
@@ -1146,7 +1146,7 @@ CheckedError Parser::CheckClash(std::vector<FieldDef*> &fields,
|
|||||||
}
|
}
|
||||||
return NoError();
|
return NoError();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool compareFieldDefs(const FieldDef *a, const FieldDef *b) {
|
static bool compareFieldDefs(const FieldDef *a, const FieldDef *b) {
|
||||||
auto a_id = atoi(a->attributes.Lookup("id")->constant.c_str());
|
auto a_id = atoi(a->attributes.Lookup("id")->constant.c_str());
|
||||||
auto b_id = atoi(b->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();
|
if (Is(';')) NEXT();
|
||||||
// Protobuf allows them to be specified in any order, so sort afterwards.
|
// Protobuf allows them to be specified in any order, so sort afterwards.
|
||||||
auto &v = enum_def->vals.vec;
|
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.
|
// Temp: remove any duplicates, as .fbs files can't handle them.
|
||||||
for (auto it = v.begin(); it != v.end(); ) {
|
for (auto it = v.begin(); it != v.end(); ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user