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

@@ -1436,6 +1436,12 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
int KeyCompareWithValue(const char *_name) const {
return strcmp(name()->c_str(), _name);
}
template<typename StringType>
int KeyCompareWithValue(const StringType& _name) const {
if (name()->c_str() < _name) return -1;
if (_name < name()->c_str()) return 1;
return 0;
}
const ::flatbuffers::Vector<uint8_t> *inventory() const {
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
}