[Bug c/112539] a struct with an array of unknown size at the end allows writing past end of the struct
xry111 at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Nov 15 09:39:07 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112539
--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Xi Ruoyao from comment #3)
> This invalid bug report is actually not related to flexible array member.
> It's just invoking an undefined behavior. With -fsanitize=undefined
> -fno-sanitize-recover:
Note that the "Enter Bug" page has a red banner referring to
https://gcc.gnu.org/bugs/, and this page says:
If compiling with -fsanitize=undefined produces any run-time errors, then your
code is probably not correct.
> In C even
>
> int a[1];
> return a[114514];
>
> will compile.
Correction: technically it should be "may compile". The compiler is also
allowed to reject programs which *always* invokes an undefined behavior. But
AFAIK no C compiler really rejects code because of an OOB array access as at
now.
More information about the Gcc-bugs
mailing list