mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Fixed required field checking incorrectly using unsigned offsets.
Reported by: https://github.com/google/flatbuffers/issues/99 Change-Id: Ia26da95bbac189836c257fa85f3bec1b153b6207 Tested: on Linux.
This commit is contained in:
@@ -515,7 +515,7 @@ class FlatBufferBuilder {
|
||||
uoffset_t EndTable(uoffset_t start, voffset_t numfields) {
|
||||
// Write the vtable offset, which is the start of any Table.
|
||||
// We fill it's value later.
|
||||
auto vtableoffsetloc = PushElement<uoffset_t>(0);
|
||||
auto vtableoffsetloc = PushElement<soffset_t>(0);
|
||||
// Write a vtable, which consists entirely of voffset_t elements.
|
||||
// It starts with the number of offsets, followed by a type id, followed
|
||||
// by the offsets themselves. In reverse:
|
||||
@@ -564,7 +564,7 @@ class FlatBufferBuilder {
|
||||
// just been constructed.
|
||||
template<typename T> void Required(Offset<T> table, voffset_t field) {
|
||||
auto table_ptr = buf_.data_at(table.o);
|
||||
auto vtable_ptr = table_ptr - ReadScalar<uoffset_t>(table_ptr);
|
||||
auto vtable_ptr = table_ptr - ReadScalar<soffset_t>(table_ptr);
|
||||
bool ok = ReadScalar<voffset_t>(vtable_ptr + field) != 0;
|
||||
// If this fails, the caller will show what field needs to be set.
|
||||
assert(ok);
|
||||
|
||||
Reference in New Issue
Block a user