Skip to content

Commit 1ea6a99

Browse files
committed
Stack allocate aligned buffers in monster_test.c
Signed-off-by: Björn Svensson <[email protected]>
1 parent b528135 commit 1ea6a99

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/monster_test/monster_test.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,11 @@ int verify_include(void *buffer)
25352535

25362536
int test_struct_buffer(flatcc_builder_t *B)
25372537
{
2538-
uint8_t buffer[100];
2538+
/* Allocate a buffer and make sure it's aligned on targets that don't
2539+
* use a 16 bytes stack alignment (e.g. 32-bit/x86 and s390x).
2540+
* This will avoid an undefined behaviour in this testcase:
2541+
* "member access within misaligned address". */
2542+
alignas(16) uint8_t buffer[100];
25392543

25402544
size_t size;
25412545
ns(Vec3_t) *v;
@@ -2584,7 +2588,11 @@ int test_struct_buffer(flatcc_builder_t *B)
25842588

25852589
int test_typed_struct_buffer(flatcc_builder_t *B)
25862590
{
2587-
uint8_t buffer[100];
2591+
/* Allocate a buffer and make sure it's aligned on targets that don't
2592+
* use a 16 bytes stack alignment (e.g. 32-bit/x86 and s390x).
2593+
* This will avoid an undefined behaviour in this testcase:
2594+
* "member access within misaligned address". */
2595+
alignas(16) uint8_t buffer[100];
25882596

25892597
size_t size;
25902598
ns(Vec3_t) *v;

0 commit comments

Comments
 (0)