diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index b8a05a920..5234c4f25 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -603,7 +603,7 @@ class FlatBufferBuilder { template Offset> CreateVectorOfStructs( const T *v, size_t len) { NotNested(); - StartVector(len, AlignOf()); + StartVector(len * sizeof(T) / AlignOf(), AlignOf()); PushBytes(reinterpret_cast(v), sizeof(T) * len); return Offset>(EndVector(len)); } diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 1d9018eb8..b7cb61490 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -446,9 +446,13 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) { #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ case BASE_TYPE_ ## ENUM: \ builder_.Pad(field->padding); \ - builder_.AddElement(value.offset, \ + if (struct_def.fixed) { \ + builder_.PushElement(atot(value.constant.c_str())); \ + } else { \ + builder_.AddElement(value.offset, \ atot( value.constant.c_str()), \ atot(field->value.constant.c_str())); \ + } \ break; FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD); #undef FLATBUFFERS_TD @@ -501,7 +505,8 @@ uoffset_t Parser::ParseVector(const Type &type) { } Next(); - builder_.StartVector(count * InlineSize(type), InlineAlignment((type))); + builder_.StartVector(count * InlineSize(type) / InlineAlignment(type), + InlineAlignment(type)); for (int i = 0; i < count; i++) { // start at the back, since we're building the data backwards. auto &val = field_stack_.back().first;