Fix incorrect padding in arrays of structs (Issue #5484) (#5491)

This commit is contained in:
svenk177
2019-08-23 19:46:47 +02:00
committed by Wouter van Oortmerssen
parent b97b342f59
commit 4525c91be3
16 changed files with 228 additions and 57 deletions

View File

@@ -62,12 +62,13 @@ inline const char *EnumNameTestEnum(TestEnum e) {
return EnumNamesTestEnum()[index];
}
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) NestedStruct FLATBUFFERS_FINAL_CLASS {
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) NestedStruct FLATBUFFERS_FINAL_CLASS {
private:
int32_t a_[2];
int8_t b_;
int8_t c_[2];
int8_t padding0__;
int8_t padding0__; int32_t padding1__;
int64_t d_[2];
public:
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
@@ -80,7 +81,8 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) NestedStruct FLATBUFFERS_FINAL_CLASS {
: b_(flatbuffers::EndianScalar(static_cast<int8_t>(_b))) {
std::memset(a_, 0, sizeof(a_));
std::memset(c_, 0, sizeof(c_));
(void)padding0__;
(void)padding0__; (void)padding1__;
std::memset(d_, 0, sizeof(d_));
}
const flatbuffers::Array<int32_t, 2> *a() const {
return reinterpret_cast<const flatbuffers::Array<int32_t, 2> *>(a_);
@@ -100,14 +102,21 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) NestedStruct FLATBUFFERS_FINAL_CLASS {
flatbuffers::Array<MyGame::Example::TestEnum, 2> *mutable_c() {
return reinterpret_cast<flatbuffers::Array<MyGame::Example::TestEnum, 2> *>(c_);
}
const flatbuffers::Array<int64_t, 2> *d() const {
return reinterpret_cast<const flatbuffers::Array<int64_t, 2> *>(d_);
}
flatbuffers::Array<int64_t, 2> *mutable_d() {
return reinterpret_cast<flatbuffers::Array<int64_t, 2> *>(d_);
}
};
FLATBUFFERS_STRUCT_END(NestedStruct, 12);
FLATBUFFERS_STRUCT_END(NestedStruct, 32);
inline bool operator==(const NestedStruct &lhs, const NestedStruct &rhs) {
return
(lhs.a() == rhs.a()) &&
(lhs.b() == rhs.b()) &&
(lhs.c() == rhs.c());
(lhs.c() == rhs.c()) &&
(lhs.d() == rhs.d());
}
inline bool operator!=(const NestedStruct &lhs, const NestedStruct &rhs) {
@@ -115,13 +124,16 @@ inline bool operator!=(const NestedStruct &lhs, const NestedStruct &rhs) {
}
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) ArrayStruct FLATBUFFERS_FINAL_CLASS {
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) ArrayStruct FLATBUFFERS_FINAL_CLASS {
private:
float a_;
int32_t b_[15];
int8_t c_;
int8_t padding0__; int16_t padding1__;
int8_t padding0__; int16_t padding1__; int32_t padding2__;
MyGame::Example::NestedStruct d_[2];
int32_t e_;
int32_t padding3__;
int64_t f_[2];
public:
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
@@ -130,14 +142,19 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) ArrayStruct FLATBUFFERS_FINAL_CLASS {
ArrayStruct() {
memset(static_cast<void *>(this), 0, sizeof(ArrayStruct));
}
ArrayStruct(float _a, int8_t _c)
ArrayStruct(float _a, int8_t _c, int32_t _e)
: a_(flatbuffers::EndianScalar(_a)),
c_(flatbuffers::EndianScalar(_c)),
padding0__(0),
padding1__(0) {
padding1__(0),
padding2__(0),
e_(flatbuffers::EndianScalar(_e)),
padding3__(0) {
std::memset(b_, 0, sizeof(b_));
(void)padding0__; (void)padding1__;
(void)padding0__; (void)padding1__; (void)padding2__;
std::memset(d_, 0, sizeof(d_));
(void)padding3__;
std::memset(f_, 0, sizeof(f_));
}
float a() const {
return flatbuffers::EndianScalar(a_);
@@ -163,15 +180,29 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) ArrayStruct FLATBUFFERS_FINAL_CLASS {
flatbuffers::Array<MyGame::Example::NestedStruct, 2> *mutable_d() {
return reinterpret_cast<flatbuffers::Array<MyGame::Example::NestedStruct, 2> *>(d_);
}
int32_t e() const {
return flatbuffers::EndianScalar(e_);
}
void mutate_e(int32_t _e) {
flatbuffers::WriteScalar(&e_, _e);
}
const flatbuffers::Array<int64_t, 2> *f() const {
return reinterpret_cast<const flatbuffers::Array<int64_t, 2> *>(f_);
}
flatbuffers::Array<int64_t, 2> *mutable_f() {
return reinterpret_cast<flatbuffers::Array<int64_t, 2> *>(f_);
}
};
FLATBUFFERS_STRUCT_END(ArrayStruct, 92);
FLATBUFFERS_STRUCT_END(ArrayStruct, 160);
inline bool operator==(const ArrayStruct &lhs, const ArrayStruct &rhs) {
return
(lhs.a() == rhs.a()) &&
(lhs.b() == rhs.b()) &&
(lhs.c() == rhs.c()) &&
(lhs.d() == rhs.d());
(lhs.d() == rhs.d()) &&
(lhs.e() == rhs.e()) &&
(lhs.f() == rhs.f());
}
inline bool operator!=(const ArrayStruct &lhs, const ArrayStruct &rhs) {
@@ -298,19 +329,21 @@ inline const flatbuffers::TypeTable *NestedStructTypeTable() {
static const flatbuffers::TypeCode type_codes[] = {
{ flatbuffers::ET_SEQUENCE, 0, -1 },
{ flatbuffers::ET_CHAR, 0, 0 },
{ flatbuffers::ET_SEQUENCE, 0, 0 }
{ flatbuffers::ET_SEQUENCE, 0, 0 },
{ flatbuffers::ET_SEQUENCE, 0, -1 }
};
static const flatbuffers::TypeFunction type_refs[] = {
MyGame::Example::TestEnumTypeTable
};
static const int64_t values[] = { 0, 8, 9, 12 };
static const int64_t values[] = { 0, 8, 9, 16, 32 };
static const char * const names[] = {
"a",
"b",
"c"
"c",
"d"
};
static const flatbuffers::TypeTable tt = {
flatbuffers::ST_STRUCT, 3, type_codes, type_refs, values, names
flatbuffers::ST_STRUCT, 4, type_codes, type_refs, values, names
};
return &tt;
}
@@ -320,20 +353,24 @@ inline const flatbuffers::TypeTable *ArrayStructTypeTable() {
{ flatbuffers::ET_FLOAT, 0, -1 },
{ flatbuffers::ET_SEQUENCE, 0, -1 },
{ flatbuffers::ET_CHAR, 0, -1 },
{ flatbuffers::ET_SEQUENCE, 0, 0 }
{ flatbuffers::ET_SEQUENCE, 0, 0 },
{ flatbuffers::ET_INT, 0, -1 },
{ flatbuffers::ET_SEQUENCE, 0, -1 }
};
static const flatbuffers::TypeFunction type_refs[] = {
MyGame::Example::NestedStructTypeTable
};
static const int64_t values[] = { 0, 4, 64, 68, 92 };
static const int64_t values[] = { 0, 4, 64, 72, 136, 144, 160 };
static const char * const names[] = {
"a",
"b",
"c",
"d"
"d",
"e",
"f"
};
static const flatbuffers::TypeTable tt = {
flatbuffers::ST_STRUCT, 4, type_codes, type_refs, values, names
flatbuffers::ST_STRUCT, 6, type_codes, type_refs, values, names
};
return &tt;
}