Skip to content

Commit

Permalink
fix possible null dereference for nested_root accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaileychess committed May 3, 2023
1 parent fb4f6fb commit 75143f8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
12 changes: 9 additions & 3 deletions tests/cpp17/generated_cpp17/monster_test_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER);
}
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 {
return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY);
Expand Down Expand Up @@ -1605,7 +1607,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX);
}
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 {
return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5);
Expand Down Expand Up @@ -1735,7 +1739,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER);
}
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 {
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES);
Expand Down
12 changes: 9 additions & 3 deletions tests/monster_test_suffix/ext_only/monster_test_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER);
}
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 {
return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY);
Expand Down Expand Up @@ -1592,7 +1594,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX);
}
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 {
return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5);
Expand Down Expand Up @@ -1722,7 +1726,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER);
}
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 {
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES);
Expand Down
12 changes: 9 additions & 3 deletions tests/monster_test_suffix/filesuffix_only/monster_test_suffix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER);
}
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 {
return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY);
Expand Down Expand Up @@ -1592,7 +1594,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX);
}
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 {
return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5);
Expand Down Expand Up @@ -1722,7 +1726,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER);
}
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 {
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES);
Expand Down
12 changes: 9 additions & 3 deletions tests/monster_test_suffix/monster_test_suffix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER);
}
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 {
return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY);
Expand Down Expand Up @@ -1592,7 +1594,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX);
}
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 {
return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5);
Expand Down Expand Up @@ -1722,7 +1726,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER);
}
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 {
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES);
Expand Down

0 comments on commit 75143f8

Please sign in to comment.