Made the memcmp address sanitizer clean.

Added extra check to ensure memcmp gets called with a size that is
guaranteed within range of the buffer. This wasn't a real problem,
but stops address sanitizer from complaining.

See:
https://github.com/google/flatbuffers/issues/88
517506b4e1 (commitcomment-8265231)

Change-Id: I7de24da2d36d973e154f92eeb3e093070886037f
Tested: on Linux
This commit is contained in:
Wouter van Oortmerssen
2014-11-07 15:24:22 -08:00
parent 8ef6ee2a3e
commit 6ca102e413

View File

@@ -540,7 +540,9 @@ class FlatBufferBuilder {
// See if we already have generated a vtable with this exact same
// layout before. If so, make it point to the old one, remove this one.
for (auto it = vtables_.begin(); it != vtables_.end(); ++it) {
if (memcmp(buf_.data_at(*it), vt1, vt1_size)) continue;
auto vt2 = reinterpret_cast<voffset_t *>(buf_.data_at(*it));
auto vt2_size = *vt2;
if (vt1_size != vt2_size || memcmp(vt2, vt1, vt1_size)) continue;
vt_use = *it;
buf_.pop(GetSize() - vtableoffsetloc);
break;