Ensure appropriate minimum alignment on flatbuffer tables
If you had a table whose fields all had alignments of <4 bytes, the
overall table still needed to have 4 byte alignment to account for the
various offsets included in every table.
Change-Id: I7c39c647d79dff80732f84c4e530319ee8f20c99
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/flatbuffers/static_flatbuffers_test.cc b/aos/flatbuffers/static_flatbuffers_test.cc
index 61ec118..acea168 100644
--- a/aos/flatbuffers/static_flatbuffers_test.cc
+++ b/aos/flatbuffers/static_flatbuffers_test.cc
@@ -818,6 +818,15 @@
TestMemory(builder.buffer());
}
+TEST_F(StaticFlatbuffersTest, MinimallyAlignedTable) {
+ VerifyJson<MinimallyAlignedTableStatic>("{\n \"field\": 123\n}");
+ static_assert(4u == alignof(uoffset_t),
+ "The alignment of a uoffset_t is expected to be 4.");
+ ASSERT_EQ(alignof(uoffset_t), MinimallyAlignedTableStatic::kAlign)
+ << "No table should have an alignment of less than the alignment of the "
+ "table's root offset.";
+}
+
// Confirm that we can use the SpanAllocator with a span that provides exactly
// the required buffer size.
TEST_F(StaticFlatbuffersTest, ExactSizeSpanAllocator) {