Fixed required field checking incorrectly using unsigned offsets.

Reported by: https://github.com/google/flatbuffers/issues/99

Change-Id: Ia26da95bbac189836c257fa85f3bec1b153b6207
Tested: on Linux.
parent 118abc28
...@@ -515,7 +515,7 @@ class FlatBufferBuilder { ...@@ -515,7 +515,7 @@ class FlatBufferBuilder {
uoffset_t EndTable(uoffset_t start, voffset_t numfields) { uoffset_t EndTable(uoffset_t start, voffset_t numfields) {
// Write the vtable offset, which is the start of any Table. // Write the vtable offset, which is the start of any Table.
// We fill it's value later. // 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. // Write a vtable, which consists entirely of voffset_t elements.
// It starts with the number of offsets, followed by a type id, followed // It starts with the number of offsets, followed by a type id, followed
// by the offsets themselves. In reverse: // by the offsets themselves. In reverse:
...@@ -564,7 +564,7 @@ class FlatBufferBuilder { ...@@ -564,7 +564,7 @@ class FlatBufferBuilder {
// just been constructed. // just been constructed.
template<typename T> void Required(Offset<T> table, voffset_t field) { template<typename T> void Required(Offset<T> table, voffset_t field) {
auto table_ptr = buf_.data_at(table.o); 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; bool ok = ReadScalar<voffset_t>(vtable_ptr + field) != 0;
// If this fails, the caller will show what field needs to be set. // If this fails, the caller will show what field needs to be set.
assert(ok); assert(ok);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment