Skip to content

Commit 0986e28

Browse files
committed
auto/clang: Added NJS_NONSTRING macro.
This is a wrapper around __attribute__((nonstring)). Traditionally this was used to mark char array variables that intentionally lacked a terminating NUL byte, this would then cause warnings to either be quelled or emitted for various memory/string functions. GCC 15 introduced a new warning, Wunterminated-string-initialization, which will always warn on things like static const char hex[16] = "0123456789ABCDEF"; However this is very much intentionally not NUL terminated. The above attribute also quells this new warning (which is also enabled by -Wextra). So the above example would become static const char hex[16] NJS_NONSTRING = "0123456789ABCDEF"; Link: <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=44c9403ed1833ae71a59e84f9e37af3182be0df5> Link: <https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=622968990beee7499e951590258363545b4a3b57> Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178#c21> Signed-off-by: Andrew Clayton <[email protected]>
1 parent dbf556f commit 0986e28

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

auto/clang

+14
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ njs_feature_test="__attribute__((no_sanitize(\"undefined\"))) int main(void) {
172172
. auto/feature
173173

174174

175+
njs_feature="GCC __attribute__ nonstring"
176+
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_NONSTRING
177+
njs_feature_run=
178+
njs_feature_incs=
179+
njs_feature_libs=
180+
njs_feature_test="int main(void) {
181+
static const char str[3] __attribute__((nonstring)) =
182+
\"ABC\";
183+
184+
return !!str[0];
185+
}"
186+
. auto/feature
187+
188+
175189
njs_feature="Address sanitizer"
176190
njs_feature_name=NJS_HAVE_ADDRESS_SANITIZER
177191
njs_feature_run=no

src/njs_clang.h

+8
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ njs_leading_zeros64(uint64_t x)
162162
#endif
163163

164164

165+
#if (NJS_HAVE_GCC_ATTRIBUTE_NONSTRING)
166+
#define NJS_NONSTRING __attribute__((nonstring))
167+
168+
#else
169+
#define NJS_NONSTRING
170+
#endif
171+
172+
165173
#if (NJS_CLANG)
166174
/* Any __asm__ directive disables loop vectorization in GCC and Clang. */
167175
#define njs_pragma_loop_disable_vectorization __asm__("")

0 commit comments

Comments
 (0)