Catch more invalid corner cases in JsonToFlatbuffer
If you had something which was supposed to be an array of tables and the
JSON was just an object, then there were no obvious errors until you got
a mangled flatbuffer at the end.
Change-Id: I8f584c8a75ec711231cb385fa4439966a0fdafa9
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/json_to_flatbuffer.cc b/aos/json_to_flatbuffer.cc
index 825bb3c..fa1cf62 100644
--- a/aos/json_to_flatbuffer.cc
+++ b/aos/json_to_flatbuffer.cc
@@ -215,6 +215,14 @@
return false;
}
+ if (in_vector() != stack_.back().type.FieldIsRepeating(field_index)) {
+ fprintf(stderr,
+ "Field '%s' is%s supposed to be a vector, but is a %s.\n",
+ stack_.back().field_name.c_str(), in_vector() ? " not" : "",
+ in_vector() ? "vector" : "bare object");
+ return false;
+ }
+
stack_.push_back({stack_.back().type.FieldType(field_index),
false,
-1,