From: Wouter van Oortmerssen Date: Wed, 3 Sep 2014 21:48:37 +0000 (-0700) Subject: Setting a field twice in a JSON object now gives error. X-Git-Tag: v1.0.2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57b614587c45ce5751ef5533c34131273be01cf2;p=platform%2Fupstream%2Fflatbuffers.git 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. --- diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 9911fab..4c60fd7 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -457,6 +457,10 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) { || struct_def.fields.vec[fieldn] != field)) { 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(':'); Value val = field->value; ParseAnyValue(val, field); diff --git a/tests/test.cpp b/tests/test.cpp index 03955e3..4cd4fd1 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -490,6 +490,7 @@ void ErrorTest() { TestError("union Z { X } struct X { Y:int; }", "only tables"); TestError("table X { Y:[int]; YLength:int; }", "clash"); 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.