[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
alx at kernel dot org
gcc-bugzilla@gcc.gnu.org
Fri Mar 7 23:26:14 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
--- Comment #29 from Alejandro Colomar <alx at kernel dot org> ---
Hi Kees,
(In reply to GCC Commits from comment #28)
> The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
>
> https://gcc.gnu.org/g:622968990beee7499e951590258363545b4a3b57
I guess I should have reviewed the commit message when I was in time. Anyway,
here are a few comments for next time. :-)
>
> commit r15-7900-g622968990beee7499e951590258363545b4a3b57
> Author: Jakub Jelinek <jakub@redhat.com>
> Date: Fri Mar 7 23:59:34 2025 +0100
>
> c: do not warn about truncating NUL char when initializing nonstring
> arrays [PR117178]
>
> When initializing a nonstring char array when compiled with
> -Wunterminated-string-initialization the warning trips even when
> truncating the trailing NUL character from the string constant. Only
> warn about this when running under -Wc++-compat since under C++ we should
> not initialize nonstrings from C strings.
The paragraph above is a bit unclear. If I'm understanding it correctly, I
think the first sentence refers to the behavior before this patch? If so,
using past might have been clearer.
> gcc/c/
> * c-typeck.cc (digest_init): Add DECL argument. Adjust wording
> of
> pedwarn_init for too long strings and provide details on the
> lengths,
> for string literals where just the trailing NULL doesn't fit
> warn for
NULL is the null pointer constant. You meant NUL, which is the ASCII name for
the null byte.
Cheers,
Alex
More information about the Gcc-bugs
mailing list