Setting a field twice in a JSON object now gives error.

Before, it would crash in FlatBufferBuilder.

Bug: 17357164
Change-Id: I6e6dbada5261745220345379eb53eb3eb113e8f8
Tested: on Linux.
parent 15dc1a86
...@@ -457,6 +457,10 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) { ...@@ -457,6 +457,10 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) {
|| struct_def.fields.vec[fieldn] != field)) { || struct_def.fields.vec[fieldn] != field)) {
Error("struct field appearing out of order: " + name); Error("struct field appearing out of order: " + name);
} }
for (auto it = field_stack_.rbegin();
it != field_stack_.rbegin() + fieldn; ++it) {
if (it->second == field) Error("field already set: " + name);
}
Expect(':'); Expect(':');
Value val = field->value; Value val = field->value;
ParseAnyValue(val, field); ParseAnyValue(val, field);
......
...@@ -490,6 +490,7 @@ void ErrorTest() { ...@@ -490,6 +490,7 @@ void ErrorTest() {
TestError("union Z { X } struct X { Y:int; }", "only tables"); TestError("union Z { X } struct X { Y:int; }", "only tables");
TestError("table X { Y:[int]; YLength:int; }", "clash"); TestError("table X { Y:[int]; YLength:int; }", "clash");
TestError("table X { Y:string = 1; }", "scalar"); TestError("table X { Y:string = 1; }", "scalar");
TestError("table X { Y:byte; } root_type X; { Y:1, Y:2 }", "already set");
} }
// Additional parser testing not covered elsewhere. // Additional parser testing not covered elsewhere.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment