mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 04:21:13 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user