Building a Gnulib testdir with a GCC 15 snapshot and "-Wall -Wextra", I see these warnings:
../../gllib/base32.c:69:5: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (33 chars into 32 available) ../../gllib/base64.c:63:3: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (65 chars into 64 available) ../../gllib/bcp47.c:104:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) ../../gllib/bcp47.c:106:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) ../../gllib/bcp47.c:108:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) ../../gllib/bcp47.c:110:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) ../../gllib/bcp47.c:112:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) ../../gllib/bcp47.c:114:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) ../../gllib/bcp47.c:116:19: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (5 chars into 4 available) ../../gllib/striconveh.c:795:57: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) unicase/special-casing-table.gperf:39:8: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) ... unicase/special-casing-table.gperf:160:8: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) Since -Wunterminated-string-initialization is reasonable to enable, here is a patch to silence the warning where it currently occurs (excluding in the tests). 2025-04-02 Bruno Haible <br...@clisp.org> Silence some -Wunterminated-string-initialization warnings. * lib/base32.c (base32_encode): Mark b32str as not NUL-terminated. * lib/base64.c (b64c): Mark as not NUL-terminated. * lib/bcp47.c (struct script): Mark the 'code' field as not NUL-terminated. * lib/striconveh.c (mem_cd_iconveh_internal): Mark hex as not NUL-terminated. * lib/unicase/special-casing.in.h (struct special_casing_rule): Mark the 'code' field as not NUL-terminated. diff --git a/lib/base32.c b/lib/base32.c index a89111990b..cc74f921e0 100644 --- a/lib/base32.c +++ b/lib/base32.c @@ -65,7 +65,7 @@ void base32_encode (const char *restrict in, idx_t inlen, char *restrict out, idx_t outlen) { - static const char b32str[32] = + static const char b32str[32] _GL_ATTRIBUTE_NONSTRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; while (inlen && outlen) diff --git a/lib/base64.c b/lib/base64.c index 6b1b0c2bda..8a0edd4a6e 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -59,7 +59,7 @@ to_uchar (char ch) return ch; } -static const char b64c[64] = +static const char b64c[64] _GL_ATTRIBUTE_NONSTRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* Base64 encode IN array of size INLEN into OUT array. OUT needs diff --git a/lib/bcp47.c b/lib/bcp47.c index 49bcace178..46fd31b5d4 100644 --- a/lib/bcp47.c +++ b/lib/bcp47.c @@ -91,8 +91,8 @@ struct script { - char name[12]; /* Script name, lowercased, NUL-terminated */ - char code[4]; /* Script code, not NUL-terminated */ + char name[12]; /* Script name, lowercased, NUL-terminated */ + char code[4] _GL_ATTRIBUTE_NONSTRING; /* Script code, not NUL-terminated */ }; /* Table of script names and four-letter script codes. diff --git a/lib/striconveh.c b/lib/striconveh.c index 9e8d9c8600..8730e44ef7 100644 --- a/lib/striconveh.c +++ b/lib/striconveh.c @@ -792,7 +792,8 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, if (handler == iconveh_escape_sequence) { - static char const hex[16] = "0123456789ABCDEF"; + static char const hex[16] _GL_ATTRIBUTE_NONSTRING = + "0123456789ABCDEF"; scratchlen = 0; scratchbuf[scratchlen++] = '\\'; if (uc < 0x10000) diff --git a/lib/unicase/special-casing.in.h b/lib/unicase/special-casing.in.h index d174feba65..81ec05acbc 100644 --- a/lib/unicase/special-casing.in.h +++ b/lib/unicase/special-casing.in.h @@ -46,7 +46,7 @@ struct special_casing_rule { /* The first two bytes are the code, in big-endian order. The third byte only distinguishes different rules pertaining to the same code. */ - /*unsigned*/ char code[3]; + /*unsigned*/ char code[3] _GL_ATTRIBUTE_NONSTRING; /* True when this rule is not the last one for the given code. */ /*bool*/ unsigned int has_next : 1;