mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Union verification functions were not correctly namespaced.
Bug: 18908613 Change-Id: Ifed8a33b6b976b64eed9d190d930b08de1d5f41e Tested: on Linux.
This commit is contained in:
@@ -39,6 +39,12 @@ static std::string WrapInNameSpace(const Parser &parser, const Namespace *ns,
|
||||
}
|
||||
}
|
||||
|
||||
static std::string WrapInNameSpace(const Parser &parser,
|
||||
const Definition &def) {
|
||||
return WrapInNameSpace(parser, def.defined_namespace, def.name);
|
||||
}
|
||||
|
||||
|
||||
// Return a C++ type from the table in idl.h
|
||||
static std::string GenTypeBasic(const Parser &parser, const Type &type,
|
||||
bool real_enum) {
|
||||
@@ -48,8 +54,7 @@ static std::string GenTypeBasic(const Parser &parser, const Type &type,
|
||||
#undef FLATBUFFERS_TD
|
||||
};
|
||||
return real_enum && type.enum_def
|
||||
? WrapInNameSpace(parser, type.enum_def->defined_namespace,
|
||||
type.enum_def->name)
|
||||
? WrapInNameSpace(parser, *type.enum_def)
|
||||
: ctypename[type.base_type];
|
||||
}
|
||||
|
||||
@@ -66,8 +71,7 @@ static std::string GenTypePointer(const Parser &parser, const Type &type) {
|
||||
return "flatbuffers::Vector<" +
|
||||
GenTypeWire(parser, type.VectorType(), "", false) + ">";
|
||||
case BASE_TYPE_STRUCT: {
|
||||
return WrapInNameSpace(parser, type.struct_def->defined_namespace,
|
||||
type.struct_def->name);
|
||||
return WrapInNameSpace(parser, *type.struct_def);
|
||||
}
|
||||
case BASE_TYPE_UNION:
|
||||
// fall through
|
||||
@@ -114,8 +118,8 @@ static std::string GenEnumVal(const EnumDef &enum_def, const EnumVal &enum_val,
|
||||
}
|
||||
|
||||
// Generate an enum declaration and an enum string lookup table.
|
||||
static void GenEnum(EnumDef &enum_def, std::string *code_ptr,
|
||||
std::string *code_ptr_post,
|
||||
static void GenEnum(const Parser &parser, EnumDef &enum_def,
|
||||
std::string *code_ptr, std::string *code_ptr_post,
|
||||
const GeneratorOptions &opts) {
|
||||
if (enum_def.generated) return;
|
||||
std::string &code = *code_ptr;
|
||||
@@ -180,7 +184,8 @@ static void GenEnum(EnumDef &enum_def, std::string *code_ptr,
|
||||
code_post += ": return true;\n"; // "NONE" enum value.
|
||||
} else {
|
||||
code_post += ": return verifier.VerifyTable(reinterpret_cast<const ";
|
||||
code_post += ev.struct_def->name + " *>(union_obj));\n";
|
||||
code_post += WrapInNameSpace(parser, *ev.struct_def);
|
||||
code_post += " *>(union_obj));\n";
|
||||
}
|
||||
}
|
||||
code_post += " default: return false;\n }\n}\n\n";
|
||||
@@ -517,7 +522,7 @@ std::string GenerateCPP(const Parser &parser,
|
||||
std::string enum_code, enum_code_post;
|
||||
for (auto it = parser.enums_.vec.begin();
|
||||
it != parser.enums_.vec.end(); ++it) {
|
||||
GenEnum(**it, &enum_code, &enum_code_post, opts);
|
||||
GenEnum(parser, **it, &enum_code, &enum_code_post, opts);
|
||||
}
|
||||
|
||||
// Generate forward declarations for all structs/tables, since they may
|
||||
@@ -625,38 +630,39 @@ std::string GenerateCPP(const Parser &parser,
|
||||
|
||||
// Generate convenient global helper functions:
|
||||
if (parser.root_struct_def) {
|
||||
auto &name = parser.root_struct_def->name;
|
||||
// The root datatype accessor:
|
||||
code += "inline const " + parser.root_struct_def->name + " *Get";
|
||||
code += parser.root_struct_def->name;
|
||||
code += "inline const " + name + " *Get";
|
||||
code += name;
|
||||
code += "(const void *buf) { return flatbuffers::GetRoot<";
|
||||
code += parser.root_struct_def->name + ">(buf); }\n\n";
|
||||
code += name + ">(buf); }\n\n";
|
||||
|
||||
// The root verifier:
|
||||
code += "inline bool Verify";
|
||||
code += parser.root_struct_def->name;
|
||||
code += name;
|
||||
code += "Buffer(flatbuffers::Verifier &verifier) { "
|
||||
"return verifier.VerifyBuffer<";
|
||||
code += parser.root_struct_def->name + ">(); }\n\n";
|
||||
code += name + ">(); }\n\n";
|
||||
|
||||
if (parser.file_identifier_.length()) {
|
||||
// Return the identifier
|
||||
code += "inline const char *" + parser.root_struct_def->name;
|
||||
code += "inline const char *" + name;
|
||||
code += "Identifier() { return \"" + parser.file_identifier_;
|
||||
code += "\"; }\n\n";
|
||||
|
||||
// Check if a buffer has the identifier.
|
||||
code += "inline bool " + parser.root_struct_def->name;
|
||||
code += "inline bool " + name;
|
||||
code += "BufferHasIdentifier(const void *buf) { return flatbuffers::";
|
||||
code += "BufferHasIdentifier(buf, ";
|
||||
code += parser.root_struct_def->name + "Identifier()); }\n\n";
|
||||
code += name + "Identifier()); }\n\n";
|
||||
}
|
||||
|
||||
// Finish a buffer with a given root object:
|
||||
code += "inline void Finish" + parser.root_struct_def->name;
|
||||
code += "inline void Finish" + name;
|
||||
code += "Buffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<";
|
||||
code += parser.root_struct_def->name + "> root) { fbb.Finish(root";
|
||||
code += name + "> root) { fbb.Finish(root";
|
||||
if (parser.file_identifier_.length())
|
||||
code += ", " + parser.root_struct_def->name + "Identifier()";
|
||||
code += ", " + name + "Identifier()";
|
||||
code += "); }\n\n";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user