From 48ff7294779eb3a255dce51474c20628a4b4b3dc Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Tue, 20 Oct 2015 09:36:35 -0700 Subject: [PATCH] Added assert for referring to 0 offsets. Change-Id: I7c04d934bfacd4aeaa2ba476b934dd3a62d4fc0e Tested: on Linux. --- include/flatbuffers/flatbuffers.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index 8f6933ba1..ed7a2aa8f 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -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); }