Fixed bugs that could cause struct values not to be stored or misaligned
Change-Id: Ie36fe581c000fa4571c96fafd39a9e12fa29e1ca Tested: on Linux
This commit is contained in:
parent
d8a173ddc7
commit
be3c874258
|
@ -603,7 +603,7 @@ class FlatBufferBuilder {
|
|||
template<typename T> Offset<Vector<const T *>> CreateVectorOfStructs(
|
||||
const T *v, size_t len) {
|
||||
NotNested();
|
||||
StartVector(len, AlignOf<T>());
|
||||
StartVector(len * sizeof(T) / AlignOf<T>(), AlignOf<T>());
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
|
||||
return Offset<Vector<const T *>>(EndVector(len));
|
||||
}
|
||||
|
|
|
@ -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<CTYPE>(value.constant.c_str())); \
|
||||
} else { \
|
||||
builder_.AddElement(value.offset, \
|
||||
atot<CTYPE>( value.constant.c_str()), \
|
||||
atot<CTYPE>(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;
|
||||
|
|
Loading…
Reference in New Issue