[Bug sanitizer/105141] #pragma pack(1) causes incorrect UBSAN warning

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Apr 3 21:30:07 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105141

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
To be precise, with pragma pack(1) c has alignof == 1, so it really depends on
what is before it in the section.  In the #c0 case, the diagnostic said
0x0000004040ca which means that ((uintptr_t) &c.b % 4) == 2 and so ((uintptr_t)
&c % 4) == 1 (either there is some 1 byter var before it or something similar).
If you increase the size, if the preceeding var is the same, then still
((uintptr_t) &c % 4) == 1 and for 3 byte a ((uintptr_t) &c.b % 4) == 0.


More information about the Gcc-bugs mailing list