forked from BigfootDev/flatbuffers
fix possible null dereference for nested_root accessor
This commit is contained in:
@@ -987,7 +987,7 @@ class CppGenerator : public BaseGenerator {
|
|||||||
|
|
||||||
std::string UnionVectorVerifySignature(const EnumDef &enum_def) {
|
std::string UnionVectorVerifySignature(const EnumDef &enum_def) {
|
||||||
const std::string name = Name(enum_def);
|
const std::string name = Name(enum_def);
|
||||||
const std::string & type = opts_.scoped_enums ? name : "uint8_t";
|
const std::string &type = opts_.scoped_enums ? name : "uint8_t";
|
||||||
return "bool Verify" + name + "Vector" +
|
return "bool Verify" + name + "Vector" +
|
||||||
"(::flatbuffers::Verifier &verifier, " +
|
"(::flatbuffers::Verifier &verifier, " +
|
||||||
"const ::flatbuffers::Vector<::flatbuffers::Offset<void>> "
|
"const ::flatbuffers::Vector<::flatbuffers::Offset<void>> "
|
||||||
@@ -1807,7 +1807,7 @@ class CppGenerator : public BaseGenerator {
|
|||||||
field.value.type.element != BASE_TYPE_UTYPE)) {
|
field.value.type.element != BASE_TYPE_UTYPE)) {
|
||||||
auto type = GenTypeNative(field.value.type, false, field);
|
auto type = GenTypeNative(field.value.type, false, field);
|
||||||
auto cpp_type = field.attributes.Lookup("cpp_type");
|
auto cpp_type = field.attributes.Lookup("cpp_type");
|
||||||
const std::string & full_type =
|
const std::string &full_type =
|
||||||
(cpp_type
|
(cpp_type
|
||||||
? (IsVector(field.value.type)
|
? (IsVector(field.value.type)
|
||||||
? "std::vector<" +
|
? "std::vector<" +
|
||||||
@@ -1954,9 +1954,10 @@ class CppGenerator : public BaseGenerator {
|
|||||||
if (!initializer_list.empty()) { initializer_list += ",\n "; }
|
if (!initializer_list.empty()) { initializer_list += ",\n "; }
|
||||||
const auto cpp_type = field->attributes.Lookup("cpp_type");
|
const auto cpp_type = field->attributes.Lookup("cpp_type");
|
||||||
const auto cpp_ptr_type = field->attributes.Lookup("cpp_ptr_type");
|
const auto cpp_ptr_type = field->attributes.Lookup("cpp_ptr_type");
|
||||||
const std::string & type_name = (cpp_type) ? cpp_type->constant
|
const std::string &type_name =
|
||||||
: GenTypeNative(type, /*invector*/ false,
|
(cpp_type) ? cpp_type->constant
|
||||||
*field, /*forcopy*/ true);
|
: GenTypeNative(type, /*invector*/ false, *field,
|
||||||
|
/*forcopy*/ true);
|
||||||
const bool is_ptr = !(IsStruct(type) && field->native_inline) ||
|
const bool is_ptr = !(IsStruct(type) && field->native_inline) ||
|
||||||
(cpp_type && cpp_ptr_type->constant != "naked");
|
(cpp_type && cpp_ptr_type->constant != "naked");
|
||||||
CodeWriter cw;
|
CodeWriter cw;
|
||||||
@@ -1976,10 +1977,10 @@ class CppGenerator : public BaseGenerator {
|
|||||||
if (vec_type.base_type == BASE_TYPE_UTYPE) continue;
|
if (vec_type.base_type == BASE_TYPE_UTYPE) continue;
|
||||||
const auto cpp_type = field->attributes.Lookup("cpp_type");
|
const auto cpp_type = field->attributes.Lookup("cpp_type");
|
||||||
const auto cpp_ptr_type = field->attributes.Lookup("cpp_ptr_type");
|
const auto cpp_ptr_type = field->attributes.Lookup("cpp_ptr_type");
|
||||||
const std::string & type_name = (cpp_type)
|
const std::string &type_name =
|
||||||
? cpp_type->constant
|
(cpp_type) ? cpp_type->constant
|
||||||
: GenTypeNative(vec_type, /*invector*/ true,
|
: GenTypeNative(vec_type, /*invector*/ true, *field,
|
||||||
*field, /*forcopy*/ true);
|
/*forcopy*/ true);
|
||||||
const bool is_ptr = IsVectorOfPointers(*field) ||
|
const bool is_ptr = IsVectorOfPointers(*field) ||
|
||||||
(cpp_type && cpp_ptr_type->constant != "naked");
|
(cpp_type && cpp_ptr_type->constant != "naked");
|
||||||
CodeWriter cw(" ");
|
CodeWriter cw(" ");
|
||||||
@@ -2733,9 +2734,10 @@ class CppGenerator : public BaseGenerator {
|
|||||||
if (!nfn.empty()) {
|
if (!nfn.empty()) {
|
||||||
code_.SetValue("CPP_NAME", nfn);
|
code_.SetValue("CPP_NAME", nfn);
|
||||||
code_ += " const {{CPP_NAME}} *{{FIELD_NAME}}_nested_root() const {";
|
code_ += " const {{CPP_NAME}} *{{FIELD_NAME}}_nested_root() const {";
|
||||||
|
code_ += " const auto _f = {{FIELD_NAME}}();";
|
||||||
code_ +=
|
code_ +=
|
||||||
" return "
|
" return _f ? ::flatbuffers::GetRoot<{{CPP_NAME}}>(_f->Data())";
|
||||||
"::flatbuffers::GetRoot<{{CPP_NAME}}>({{FIELD_NAME}}()->Data());";
|
code_ += " : nullptr;";
|
||||||
code_ += " }";
|
code_ += " }";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2745,9 +2747,9 @@ class CppGenerator : public BaseGenerator {
|
|||||||
" const {";
|
" const {";
|
||||||
// Both Data() and size() are const-methods, therefore call order
|
// Both Data() and size() are const-methods, therefore call order
|
||||||
// doesn't matter.
|
// doesn't matter.
|
||||||
code_ +=
|
code_ += " const auto _f = {{FIELD_NAME}}();";
|
||||||
" return flexbuffers::GetRoot({{FIELD_NAME}}()->Data(), "
|
code_ += " return _f ? flexbuffers::GetRoot(_f->Data(), _f->size())";
|
||||||
"{{FIELD_NAME}}()->size());";
|
code_ += " : flexbuffers::Reference();";
|
||||||
code_ += " }";
|
code_ += " }";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2835,8 +2837,9 @@ class CppGenerator : public BaseGenerator {
|
|||||||
// Generate code to do force_align for the vector.
|
// Generate code to do force_align for the vector.
|
||||||
if (align > 1) {
|
if (align > 1) {
|
||||||
const auto vtype = field.value.type.VectorType();
|
const auto vtype = field.value.type.VectorType();
|
||||||
const std::string & type = IsStruct(vtype) ? WrapInNameSpace(*vtype.struct_def)
|
const std::string &type = IsStruct(vtype)
|
||||||
: GenTypeWire(vtype, "", false);
|
? WrapInNameSpace(*vtype.struct_def)
|
||||||
|
: GenTypeWire(vtype, "", false);
|
||||||
return "_fbb.ForceVectorAlignment(" + field_size + ", sizeof(" + type +
|
return "_fbb.ForceVectorAlignment(" + field_size + ", sizeof(" + type +
|
||||||
"), " + std::to_string(static_cast<long long>(align)) + ");";
|
"), " + std::to_string(static_cast<long long>(align)) + ");";
|
||||||
}
|
}
|
||||||
@@ -3357,8 +3360,9 @@ class CppGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
case BASE_TYPE_UTYPE: {
|
case BASE_TYPE_UTYPE: {
|
||||||
value = StripUnionType(value);
|
value = StripUnionType(value);
|
||||||
const std::string & type = opts_.scoped_enums ? Name(*field.value.type.enum_def)
|
const std::string &type = opts_.scoped_enums
|
||||||
: "uint8_t";
|
? Name(*field.value.type.enum_def)
|
||||||
|
: "uint8_t";
|
||||||
auto enum_value = "__va->_" + value + "[i].type";
|
auto enum_value = "__va->_" + value + "[i].type";
|
||||||
if (!opts_.scoped_enums)
|
if (!opts_.scoped_enums)
|
||||||
enum_value = "static_cast<uint8_t>(" + enum_value + ")";
|
enum_value = "static_cast<uint8_t>(" + enum_value + ")";
|
||||||
@@ -3424,7 +3428,7 @@ class CppGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// _o->field ? CreateT(_fbb, _o->field.get(), _rehasher);
|
// _o->field ? CreateT(_fbb, _o->field.get(), _rehasher);
|
||||||
const std::string & type = field.value.type.struct_def->name;
|
const std::string &type = field.value.type.struct_def->name;
|
||||||
code += value + " ? Create" + type;
|
code += value + " ? Create" + type;
|
||||||
code += "(_fbb, " + value;
|
code += "(_fbb, " + value;
|
||||||
if (!field.native_inline) code += GenPtrGet(field);
|
if (!field.native_inline) code += GenPtrGet(field);
|
||||||
@@ -3810,7 +3814,7 @@ class CppGenerator : public BaseGenerator {
|
|||||||
const auto field_type = GenTypeGet(type, " ", is_array ? "" : "const ",
|
const auto field_type = GenTypeGet(type, " ", is_array ? "" : "const ",
|
||||||
is_array ? "" : " &", true);
|
is_array ? "" : " &", true);
|
||||||
auto member = Name(*field) + "_";
|
auto member = Name(*field) + "_";
|
||||||
const std::string & value =
|
const std::string &value =
|
||||||
is_scalar ? "::flatbuffers::EndianScalar(" + member + ")" : member;
|
is_scalar ? "::flatbuffers::EndianScalar(" + member + ")" : member;
|
||||||
|
|
||||||
code_.SetValue("FIELD_NAME", Name(*field));
|
code_.SetValue("FIELD_NAME", Name(*field));
|
||||||
|
|||||||
@@ -1487,7 +1487,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
|||||||
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER);
|
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER);
|
||||||
}
|
}
|
||||||
const MyGame::Example::Monster *testnestedflatbuffer_nested_root() const {
|
const MyGame::Example::Monster *testnestedflatbuffer_nested_root() const {
|
||||||
return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testnestedflatbuffer()->Data());
|
const auto _f = testnestedflatbuffer();
|
||||||
|
return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data())
|
||||||
|
: nullptr;
|
||||||
}
|
}
|
||||||
const MyGame::Example::Stat *testempty() const {
|
const MyGame::Example::Stat *testempty() const {
|
||||||
return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY);
|
return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY);
|
||||||
@@ -1592,7 +1594,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
|||||||
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX);
|
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX);
|
||||||
}
|
}
|
||||||
flexbuffers::Reference flex_flexbuffer_root() const {
|
flexbuffers::Reference flex_flexbuffer_root() const {
|
||||||
return flexbuffers::GetRoot(flex()->Data(), flex()->size());
|
const auto _f = flex();
|
||||||
|
return _f ? flexbuffers::GetRoot(_f->Data(), _f->size())
|
||||||
|
: flexbuffers::Reference();
|
||||||
}
|
}
|
||||||
const ::flatbuffers::Vector<const MyGame::Example::Test *> *test5() const {
|
const ::flatbuffers::Vector<const MyGame::Example::Test *> *test5() const {
|
||||||
return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5);
|
return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5);
|
||||||
@@ -1722,7 +1726,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
|||||||
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER);
|
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER);
|
||||||
}
|
}
|
||||||
const MyGame::Example::Monster *testrequirednestedflatbuffer_nested_root() const {
|
const MyGame::Example::Monster *testrequirednestedflatbuffer_nested_root() const {
|
||||||
return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testrequirednestedflatbuffer()->Data());
|
const auto _f = testrequirednestedflatbuffer();
|
||||||
|
return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data())
|
||||||
|
: nullptr;
|
||||||
}
|
}
|
||||||
const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *scalar_key_sorted_tables() const {
|
const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *scalar_key_sorted_tables() const {
|
||||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES);
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES);
|
||||||
|
|||||||
Reference in New Issue
Block a user