Fix handling non null-terminated string_views in LookupByKey (#8203)

* Reproduce the error in a unit test

Reproduces #8200

* Overload KeyCompareWithValue to work for string-like objects

This fixes #8200.

* Extra tests

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
mpawlowski-eyeo
2024-03-25 18:39:51 +01:00
committed by GitHub
parent 67eb95de92
commit 0cfb7eb80b
9 changed files with 117 additions and 0 deletions

View File

@@ -598,6 +598,12 @@ struct FooTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
int KeyCompareWithValue(const char *_c) const {
return strcmp(c()->c_str(), _c);
}
template<typename StringType>
int KeyCompareWithValue(const StringType& _c) const {
if (c()->c_str() < _c) return -1;
if (_c < c()->c_str()) return 1;
return 0;
}
const ::flatbuffers::Vector<const keyfield::sample::Baz *> *d() const {
return GetPointer<const ::flatbuffers::Vector<const keyfield::sample::Baz *> *>(VT_D);
}