https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
Bug ID: 117178
Summary: -Wunterminated-string-initialization should ignore
trailing NUL byte for nonstring char arrays
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: kees at outflux dot net
Target Milestone: ---
The Linux kernel initializes many non-C-string char arrays with literals (e.g.
the ACPI tables have 4-character identifiers that are not NUL terminated).
While it would be possible to convert initializers from:
{ "BOOP", ... }
to:
{ { 'B', 'O', 'O', 'P' }, ... }
that is annoying.
It would be much better if -Wunterminated-string-initialization would stay
silent about char arrays marked with nonstring. For example, this should not
emit a diagnostic:
#include <stdio.h>
struct foo {
char tag[4] __attribute__((nonstring));
int a;
};
const struct foo instances[] = {
{ "ABCD", 4 },
};
int main(int argc, char *argv[])
{
printf("%c\n", instances[0].tag[0]);
return 0;
}