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:
Fergus Henderson
2025-11-24 12:11:32 +00:00
committed by GitHub
parent 7ea8db05d8
commit 20548ff3b6
30 changed files with 588 additions and 305 deletions

View File

@@ -395,7 +395,8 @@ struct ScalarStuff FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
else if constexpr (Index == 35) return default_enum();
else static_assert(Index != -1, "Invalid Field Index");
}
bool Verify(::flatbuffers::Verifier &verifier) const {
template <bool B = false>
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int8_t>(verifier, VT_JUST_I8, 1) &&
VerifyField<int8_t>(verifier, VT_MAYBE_I8, 1) &&
@@ -958,14 +959,16 @@ inline bool SizePrefixedScalarStuffBufferHasIdentifier(const void *buf) {
buf, ScalarStuffIdentifier(), true);
}
template <bool B = false>
inline bool VerifyScalarStuffBuffer(
::flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<optional_scalars::ScalarStuff>(ScalarStuffIdentifier());
::flatbuffers::VerifierTemplate<B> &verifier) {
return verifier.template VerifyBuffer<optional_scalars::ScalarStuff>(ScalarStuffIdentifier());
}
template <bool B = false>
inline bool VerifySizePrefixedScalarStuffBuffer(
::flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<optional_scalars::ScalarStuff>(ScalarStuffIdentifier());
::flatbuffers::VerifierTemplate<B> &verifier) {
return verifier.template VerifySizePrefixedBuffer<optional_scalars::ScalarStuff>(ScalarStuffIdentifier());
}
inline const char *ScalarStuffExtension() {