From 6ca102e41302a3ad4000ff2fe129492e6497579e Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 7 Nov 2014 15:24:22 -0800 Subject: [PATCH] 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 https://github.com/joker-eph/flatbuffers/commit/517506b4e105814e0823353c3d6561085c26a1ab#commitcomment-8265231 Change-Id: I7de24da2d36d973e154f92eeb3e093070886037f Tested: on Linux --- include/flatbuffers/flatbuffers.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index 32cb8e8e4..634fd77c4 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -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(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;