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
This commit is contained in:
Wouter van Oortmerssen 2020-02-06 11:49:39 -08:00
parent 6400c9b054
commit 8f56990f6c
1 changed files with 1 additions and 0 deletions

View File

@ -1494,6 +1494,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
// TODO: instead of asserting, could write vector with larger elements // TODO: instead of asserting, could write vector with larger elements
// instead, though that would be wasteful. // instead, though that would be wasteful.
FLATBUFFERS_ASSERT(WidthU(len) <= bit_width); FLATBUFFERS_ASSERT(WidthU(len) <= bit_width);
Align(bit_width);
if (!fixed) Write<uint64_t>(len, byte_width); if (!fixed) Write<uint64_t>(len, byte_width);
auto vloc = buf_.size(); auto vloc = buf_.size();
for (size_t i = 0; i < len; i++) Write(elems[i], byte_width); for (size_t i = 0; i < len; i++) Write(elems[i], byte_width);