Skip to contentSkip to conversation

xen/mcelog: Add __nonstring annotations for unterminated strings

PATCH In review Kees Cook 2 participants 2 messages Mar 10, 2025 – Mar 11, 2025 Xen hypervisor interface

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 xen/mcelog: 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.

---
 include/xen/interface/xen-mca.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/xen/interface/xen-mca.h +1 -1
index 464aa6b3a5f9..1c9afbe8cc26 100644
@@ -372,7 +372,7 @@ struct xen_mce {
 #define XEN_MCE_LOG_LEN 32
 
 struct xen_mce_log {
-	char signature[12]; /* "MACHINECHECK" */
+	char signature[12] __nonstring; /* "MACHINECHECK" */
 	unsigned len;	    /* = XEN_MCE_LOG_LEN */
 	unsigned next;
 	unsigned flags;
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
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 __nonstring to and correctly identify the char array as "not a C string" and thereby eliminate the warning.

Quoted 6 lines

Juergen