Date: Mon, 29 Dec 2025 12:00:06 +0000 From: Dimitry Andric <dim@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Alex Richardson <arichardson@FreeBSD.org> Subject: git: 0925033ac770 - stable/14 - cdefs.h: Introduce __nonstring attribute Message-ID: <69526d46.24f64.718b6c36@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=0925033ac7704279664c0deceaea7835bfb5cc1d commit 0925033ac7704279664c0deceaea7835bfb5cc1d Author: Alex Richardson <arichardson@FreeBSD.org> AuthorDate: 2025-12-16 18:03:44 +0000 Commit: Dimitry Andric <dim@FreeBSD.org> CommitDate: 2025-12-29 11:57:38 +0000 cdefs.h: Introduce __nonstring attribute This attribute can be used to annotate char arrays that are not supposed to be terminated with a NUL char and is needed to silence clang's new -Wunterminated-string-initialization warning. The name matches linuxkpi. Reviewed by: emaste, jhb MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D52565 (cherry picked from commit 802c6d5d61d15494a54a386dc2ffbcfefc68c8ab) --- sys/sys/cdefs.h | 7 +++++++ tools/build/cross-build/include/common/sys/cdefs.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 4af38941762c..029eff437c8e 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -558,6 +558,13 @@ #define __printf0like(fmtarg, firstvararg) #endif +/* To silence warnings about null terminator not fitting into an array. */ +#if __has_attribute(__nonstring__) +#define __nonstring __attribute__((__nonstring__)) +#else +#define __nonstring +#endif + #if defined(__GNUC__) #define __strong_reference(sym,aliassym) \ extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) diff --git a/tools/build/cross-build/include/common/sys/cdefs.h b/tools/build/cross-build/include/common/sys/cdefs.h index 3f9b7866141f..8419b53135f6 100644 --- a/tools/build/cross-build/include/common/sys/cdefs.h +++ b/tools/build/cross-build/include/common/sys/cdefs.h @@ -100,6 +100,14 @@ __attribute__((__format__(__printf0__, fmtarg, firstvararg))) #endif +#ifndef __nonstring +#if __has_attribute(__nonstring__) +#define __nonstring __attribute__((__nonstring__)) +#else +#define __nonstring +#endif +#endif + #ifndef __predict_true #define __predict_true(exp) __builtin_expect((exp), 1) #endifhome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69526d46.24f64.718b6c36>
