wifi: mwifiex: Add __nonstring annotations for unterminated strings
PATCH 1/1 wifi: mwifiex: Add __nonstring annotations for unterminated strings
When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with __nonstring to and correctly identify the char array as "not a C string" and thereby eliminate the warning.
--- drivers/net/wireless/marvell/mwifiex/cfp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/mwifiex/cfp.c +1 -1
@@ -150,7 +150,7 @@ static const u16 ac_mcs_rate_nss2[8][10] = {struct region_code_mapping {u8 code; -u8 region[IEEE80211_COUNTRY_STRING_LEN ]; + u8 region[IEEE80211_COUNTRY_STRING_LEN] __nonstring; };static struct region_code_mapping region_code_mapping_t[] = {
Signature · 1 line
2.34.1
Quoted 6 lines · Kees Cook
When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with
__nonstringto and correctly identify the char array as "not a C string" and thereby eliminate the warning.
Quoted 9 lines
Cc Brian Norris <[email protected]>Cc Francesco Dolcini <[email protected]>Cc Johannes Berg <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Allison Randal <[email protected]>Signed-off-by Kees Cook <[email protected]>
This code is kinda weird, because only 2 bytes actually end up used, and yet we explicitly initialize it with 3 non-NUL bytes.
This solutions seems fine though, as it is indeed not a C string and does not desire nor rely on a NUL byte:
Looks like Johannes already applied it anyway.