Added assert for referring to 0 offsets.

Change-Id: I7c04d934bfacd4aeaa2ba476b934dd3a62d4fc0e
Tested: on Linux.
parent 7c609378
...@@ -625,8 +625,10 @@ class FlatBufferBuilder FLATBUFFERS_FINAL_CLASS { ...@@ -625,8 +625,10 @@ class FlatBufferBuilder FLATBUFFERS_FINAL_CLASS {
// This function converts them to be relative to the current location // This function converts them to be relative to the current location
// in the buffer (when stored here), pointing upwards. // in the buffer (when stored here), pointing upwards.
uoffset_t ReferTo(uoffset_t off) { uoffset_t ReferTo(uoffset_t off) {
Align(sizeof(uoffset_t)); // To ensure GetSize() below is correct. // Align to ensure GetSize() below is correct.
assert(off <= GetSize()); // Must refer to something already in buffer. Align(sizeof(uoffset_t));
// Offset must refer to something already in buffer.
assert(off && off <= GetSize());
return GetSize() - off + sizeof(uoffset_t); return GetSize() - off + sizeof(uoffset_t);
} }
......
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