mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 20:31:23 +00:00
Schema parser: prohibit declaration of an array of pointers inside structs (#5907)
* Fix issue #5906, Prohibit declaration of an array of pointers inside structs - idl_parser.cpp: Prohibit declaration of an array of pointers inside structs - idl_gen_cpp.cpp: Extract GenStructConstructor() method from GenStruct() to simplify future modification - idl_gen_cpp.cpp: Add assert for checking of Array fields in structs on code-generation stage * Fix the error 'unused local variable' in release build * Fix: format the PR code according to coding rules * Add test-case and fix review notes
This commit is contained in:
@@ -677,9 +677,15 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
||||
Type type;
|
||||
ECHECK(ParseType(type));
|
||||
|
||||
if (struct_def.fixed && !IsScalar(type.base_type) && !IsStruct(type) &&
|
||||
!IsArray(type))
|
||||
return Error("structs_ may contain only scalar or struct fields");
|
||||
if (struct_def.fixed) {
|
||||
auto valid = IsScalar(type.base_type) || IsStruct(type);
|
||||
if (!valid && IsArray(type)) {
|
||||
const auto& elem_type = type.VectorType();
|
||||
valid |= IsScalar(elem_type.base_type) || IsStruct(elem_type);
|
||||
}
|
||||
if (!valid)
|
||||
return Error("structs may contain only scalar or struct fields");
|
||||
}
|
||||
|
||||
if (!struct_def.fixed && IsArray(type))
|
||||
return Error("fixed-length array in table must be wrapped in struct");
|
||||
|
||||
Reference in New Issue
Block a user