Clean-up nested_parser on all paths (#5179) (#5184)

* Clean-up nested_parser on all paths (#5179)

* Added test for parsing json with invalid nested flatbuffer

* Removed utf-8 BOM from test.cpp
This commit is contained in:
ll-antn
2019-03-04 22:35:10 +03:00
committed by Wouter van Oortmerssen
parent 2e865f4d4e
commit 1c7d91cc55
2 changed files with 30 additions and 7 deletions

View File

@@ -1216,8 +1216,15 @@ CheckedError Parser::ParseNestedFlatbuffer(Value &val, FieldDef *field,
nested_parser.uses_flexbuffers_ = uses_flexbuffers_;
// Parse JSON substring into new flatbuffer builder using nested_parser
if (!nested_parser.Parse(substring.c_str(), nullptr, nullptr)) {
ECHECK(Error(nested_parser.error_));
bool ok = nested_parser.Parse(substring.c_str(), nullptr, nullptr);
// Clean nested_parser to avoid deleting the elements in
// the SymbolTables on destruction
nested_parser.enums_.dict.clear();
nested_parser.enums_.vec.clear();
if (!ok) {
ECHECK(Error(nested_parser.error_));
}
// Force alignment for nested flatbuffer
builder_.ForceVectorAlignment(nested_parser.builder_.GetSize(), sizeof(uint8_t),
@@ -1226,11 +1233,6 @@ CheckedError Parser::ParseNestedFlatbuffer(Value &val, FieldDef *field,
auto off = builder_.CreateVector(nested_parser.builder_.GetBufferPointer(),
nested_parser.builder_.GetSize());
val.constant = NumToString(off.o);
// Clean nested_parser before destruction to avoid deleting the elements in
// the SymbolTables
nested_parser.enums_.dict.clear();
nested_parser.enums_.vec.clear();
}
return NoError();
}