From 8f56990f6cbb2ea260c9da3a2985568d5408d4dd Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Thu, 6 Feb 2020 11:49:39 -0800 Subject: [PATCH] FlexBuffers: C++: scalar-only typed vectors were not aligned. This means data written with older versions of this code has potentially misaligned data, which we'll need to support. This isn't a problem on most architectures, but could be on older ARM chips. To support them properly may require swapping out uses of `flatbuffers::ReadScalar` with a version that does a memcpy internally. Change-Id: Ib352aab4a586f3a8c6602fb25488dcfff61e06e0 --- include/flatbuffers/flexbuffers.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h index fee0e9931..7c179f0e6 100644 --- a/include/flatbuffers/flexbuffers.h +++ b/include/flatbuffers/flexbuffers.h @@ -1494,6 +1494,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { // TODO: instead of asserting, could write vector with larger elements // instead, though that would be wasteful. FLATBUFFERS_ASSERT(WidthU(len) <= bit_width); + Align(bit_width); if (!fixed) Write(len, byte_width); auto vloc = buf_.size(); for (size_t i = 0; i < len; i++) Write(elems[i], byte_width);