mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 16:48:05 +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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user