Skip to content

Commit

Permalink
Manually cherry-pick fix for creating vectors of structs
Browse files Browse the repository at this point in the history
This pulls in the functional fix in google/flatbuffers#7883

This fixes creation of vectors of structs with the "raw" flatbuffer API.
I observed this when writing tests for the static flatbuffer API and
discovering a discrepancy where the static flatbuffer API behaved
correctly and the existing API did not.

Change-Id: I124192b7f23cad4ae9b50366921ddb4e6a2590cd
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
  • Loading branch information
jameskuszmaul-brt committed Feb 16, 2024
1 parent d0d264d commit 2d74179
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -787,7 +787,7 @@ class FlatBufferBuilder {
/// where the vector is stored.
template<typename T>
Offset<Vector<const T *>> CreateVectorOfStructs(const T *v, size_t len) {
StartVector(len * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
StartVector(len, sizeof(T), AlignOf<T>());
if (len > 0) {
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
}
Expand Down Expand Up @@ -1211,7 +1211,7 @@ class FlatBufferBuilder {
// Allocates space for a vector of structures.
// Must be completed with EndVectorOfStructs().
template<typename T> T *StartVectorOfStructs(size_t vector_size) {
StartVector(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
StartVector(vector_size, sizeof(T), AlignOf<T>());
return reinterpret_cast<T *>(buf_.make_space(vector_size * sizeof(T)));
}

Expand Down

0 comments on commit 2d74179

Please sign in to comment.