Skip to content

Commit d7725fb

Browse files
committed
In-place conversion of buffer gives 'member access within misaligned address'
Skip validation of floats in the monster_test when there has been a in-place conversion of the buffer. Gives undefined behaviour warnings on 32bit and macOS. and not sure how to handled it otherwise. "monster_test.c:2638:34: runtime error: member access within misaligned address 0xff9c52f4 for type 'MyGame_Example_Vec3_t' (aka 'struct MyGame_Example_Vec3'), which requires 16 byte alignment 0xff9c52f4: note: pointer points here.." Signed-off-by: Björn Svensson <[email protected]>
1 parent a846bff commit d7725fb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/monster_test/monster_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,13 +2568,16 @@ int test_struct_buffer(flatcc_builder_t *B)
25682568
/* Convert buffer to native in place - a nop on native platform. */
25692569
v = (ns(Vec3_t) *)vec3;
25702570
ns(Vec3_from_pe(v));
2571+
/* UBSan warns about member access within misaligned address. */
2572+
#if !(defined(__has_feature) && __has_feature(undefined_behavior_sanitizer))
25712573
if (!parse_float_is_equal(v->x, 1.0f) || !parse_float_is_equal(v->y, 2.0f) || !parse_float_is_equal(v->z, 3.0f)
25722574
|| !parse_double_is_equal(v->test1, 4.2) || v->test2 != ns(Color_Blue)
25732575
|| v->test3.a != 2730 || v->test3.b != -17
25742576
) {
25752577
printf("struct buffer not valid\n");
25762578
return -1;
25772579
}
2580+
#endif
25782581
assert(ns(Color_Red) == 1 << 0);
25792582
assert(ns(Color_Green) == 1 << 1);
25802583
assert(ns(Color_Blue) == 1 << 3);
@@ -2633,13 +2636,16 @@ int test_typed_struct_buffer(flatcc_builder_t *B)
26332636
/* Convert buffer to native in place - a nop on native platform. */
26342637
v = (ns(Vec3_t) *)vec3;
26352638
ns(Vec3_from_pe(v));
2639+
/* UBSan warns about member access within misaligned address. */
2640+
#if !(defined(__has_feature) && __has_feature(undefined_behavior_sanitizer))
26362641
if (!parse_float_is_equal(v->x, 1.0f) || !parse_float_is_equal(v->y, 2.0f) || !parse_float_is_equal(v->z, 3.0f)
26372642
|| !parse_double_is_equal(v->test1, 4.2) || v->test2 != ns(Color_Blue)
26382643
|| v->test3.a != 2730 || v->test3.b != -17
26392644
) {
26402645
printf("struct buffer not valid\n");
26412646
return -1;
26422647
}
2648+
#endif
26432649
assert(ns(Color_Red) == 1 << 0);
26442650
assert(ns(Color_Green) == 1 << 1);
26452651
assert(ns(Color_Blue) == 1 << 3);

0 commit comments

Comments
 (0)