mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 16:00:59 +00:00
Size verifier fix 2 (#8740)
* Fixes to make SizeVerifier work. In particular change all the places in the Flatbuffers library and generated code that were using `Verifier` to instead use `VerifierTemplate<TrackBufferSize>` and wrap them all inside `template <bool TrackBufferSize = false>`. Also add unit tests for SizeVerifier. * Format using `sh scripts/clang-format-git.sh` * Use `B` rather than `TrackBufferSize` for the name of the template parameter. * Update generated files.
This commit is contained in:
@@ -118,8 +118,10 @@ template<> struct UnionTraits<Evolution::V2::TableC> {
|
||||
static const Union enum_value = Union::TableC;
|
||||
};
|
||||
|
||||
bool VerifyUnion(::flatbuffers::Verifier &verifier, const void *obj, Union type);
|
||||
bool VerifyUnionVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<Union> *types);
|
||||
template <bool B = false>
|
||||
bool VerifyUnion(::flatbuffers::VerifierTemplate<B> &verifier, const void *obj, Union type);
|
||||
template <bool B = false>
|
||||
bool VerifyUnionVector(::flatbuffers::VerifierTemplate<B> &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<Union> *types);
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Struct FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
@@ -176,7 +178,8 @@ struct TableA FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
const ::flatbuffers::String *c() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_C);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<float>(verifier, VT_A, 4) &&
|
||||
VerifyField<int32_t>(verifier, VT_B, 4) &&
|
||||
@@ -243,7 +246,8 @@ struct TableB FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
int32_t a() const {
|
||||
return GetField<int32_t>(VT_A, 0);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int32_t>(verifier, VT_A, 4) &&
|
||||
verifier.EndTable();
|
||||
@@ -288,7 +292,8 @@ struct TableC FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
const ::flatbuffers::String *b() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_B);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<double>(verifier, VT_A, 8) &&
|
||||
VerifyOffset(verifier, VT_B) &&
|
||||
@@ -397,7 +402,8 @@ struct Root FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
uint8_t l() const {
|
||||
return GetField<uint8_t>(VT_L, 56);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<uint8_t>(verifier, VT_B, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_C_TYPE, 1) &&
|
||||
@@ -538,7 +544,8 @@ inline ::flatbuffers::Offset<Root> CreateRootDirect(
|
||||
l);
|
||||
}
|
||||
|
||||
inline bool VerifyUnion(::flatbuffers::Verifier &verifier, const void *obj, Union type) {
|
||||
template <bool B>
|
||||
inline bool VerifyUnion(::flatbuffers::VerifierTemplate<B> &verifier, const void *obj, Union type) {
|
||||
switch (type) {
|
||||
case Union::NONE: {
|
||||
return true;
|
||||
@@ -559,7 +566,8 @@ inline bool VerifyUnion(::flatbuffers::Verifier &verifier, const void *obj, Unio
|
||||
}
|
||||
}
|
||||
|
||||
inline bool VerifyUnionVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<Union> *types) {
|
||||
template <bool B>
|
||||
inline bool VerifyUnionVector(::flatbuffers::VerifierTemplate<B> &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<Union> *types) {
|
||||
if (!values || !types) return !values && !types;
|
||||
if (values->size() != types->size()) return false;
|
||||
for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
@@ -579,14 +587,16 @@ inline const Evolution::V2::Root *GetSizePrefixedRoot(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Evolution::V2::Root>(buf);
|
||||
}
|
||||
|
||||
template <bool B = false>
|
||||
inline bool VerifyRootBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Evolution::V2::Root>(nullptr);
|
||||
::flatbuffers::VerifierTemplate<B> &verifier) {
|
||||
return verifier.template VerifyBuffer<Evolution::V2::Root>(nullptr);
|
||||
}
|
||||
|
||||
template <bool B = false>
|
||||
inline bool VerifySizePrefixedRootBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Evolution::V2::Root>(nullptr);
|
||||
::flatbuffers::VerifierTemplate<B> &verifier) {
|
||||
return verifier.template VerifySizePrefixedBuffer<Evolution::V2::Root>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishRootBuffer(
|
||||
|
||||
Reference in New Issue
Block a user