Added assert for referring to 0 offsets.

Change-Id: I7c04d934bfacd4aeaa2ba476b934dd3a62d4fc0e
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen 2015-10-20 09:36:35 -07:00
parent 7c60937806
commit 48ff729477
1 changed files with 4 additions and 2 deletions

View File

@ -625,8 +625,10 @@ class FlatBufferBuilder FLATBUFFERS_FINAL_CLASS {
// This function converts them to be relative to the current location
// in the buffer (when stored here), pointing upwards.
uoffset_t ReferTo(uoffset_t off) {
Align(sizeof(uoffset_t)); // To ensure GetSize() below is correct.
assert(off <= GetSize()); // Must refer to something already in buffer.
// Align to ensure GetSize() below is correct.
Align(sizeof(uoffset_t));
// Offset must refer to something already in buffer.
assert(off && off <= GetSize());
return GetSize() - off + sizeof(uoffset_t);
}