mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-01-05 08:42:11 +01:00
216 lines
7.4 KiB
Diff
216 lines
7.4 KiB
Diff
Patch-Source: https://github.com/nginx/unit/pull/1575
|
||
From 764ad73fc7e3cbbe48b259159340e063f7d7b082 Mon Sep 17 00:00:00 2001
|
||
From: Andrew Clayton <a.clayton@nginx.com>
|
||
Date: Tue, 18 Mar 2025 04:50:24 +0000
|
||
Subject: [PATCH 1/3] auto/clang: Add a NXT_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 warning 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.
|
||
|
||
When the Wunterminated-string-initialization patch went in, the
|
||
"nonstriong" attribute didn't quell this warning, however a patch has
|
||
since gone in (prior to the GCC 15 release) to enable this attribute to
|
||
quell this warning.
|
||
|
||
In Unit we disabled this new warning with an eye to being able to
|
||
re-enable it again, this patch is the first in a series to do just that.
|
||
|
||
So the above example would become
|
||
|
||
static const char hex[16] NXT_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>
|
||
Cc: Alejandro Colomar <alx@kernel.org>
|
||
Reviewed-by: Alejandro Colomar <alx@kernel.org>
|
||
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
||
---
|
||
auto/clang | 14 ++++++++++++++
|
||
src/nxt_clang.h | 11 +++++++++++
|
||
2 files changed, 25 insertions(+)
|
||
|
||
diff --git a/auto/clang b/auto/clang
|
||
index 975a6468e..fea8602ad 100644
|
||
--- a/auto/clang
|
||
+++ b/auto/clang
|
||
@@ -194,3 +194,17 @@ nxt_feature_test="static void f(void) __attribute__ ((__unused__));
|
||
return 0;
|
||
}"
|
||
. auto/feature
|
||
+
|
||
+
|
||
+nxt_feature="GCC __attribute__ nonstring"
|
||
+nxt_feature_name=NXT_HAVE_GCC_ATTRIBUTE_NONSTRING
|
||
+nxt_feature_run=
|
||
+nxt_feature_incs=
|
||
+nxt_feature_libs=
|
||
+nxt_feature_test="int main(void) {
|
||
+ static const char str[3] __attribute__ ((__nonstring__)) =
|
||
+ \"ABC\";
|
||
+
|
||
+ return !!str[0];
|
||
+ }"
|
||
+. auto/feature
|
||
diff --git a/src/nxt_clang.h b/src/nxt_clang.h
|
||
index 6803ffc8b..872f15271 100644
|
||
--- a/src/nxt_clang.h
|
||
+++ b/src/nxt_clang.h
|
||
@@ -131,6 +131,17 @@
|
||
#endif
|
||
|
||
|
||
+#if (NXT_HAVE_GCC_ATTRIBUTE_NONSTRING)
|
||
+
|
||
+#define NXT_NONSTRING __attribute__((__nonstring__))
|
||
+
|
||
+#else
|
||
+
|
||
+#define NXT_NONSTRING
|
||
+
|
||
+#endif
|
||
+
|
||
+
|
||
#if (NXT_HAVE_BUILTIN_POPCOUNT)
|
||
|
||
#define nxt_popcount __builtin_popcount
|
||
|
||
From d9c2fd793fe1e8c8fbfd7aec9af3482fa5f0dacc Mon Sep 17 00:00:00 2001
|
||
From: Andrew Clayton <a.clayton@nginx.com>
|
||
Date: Tue, 18 Mar 2025 05:09:31 +0000
|
||
Subject: [PATCH 2/3] Tag various character arrays with NXT_NONSTRING
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
In Unit we have a number of character arrays which are intentionally not
|
||
NUL terminated.
|
||
|
||
With GCC 15 this
|
||
|
||
static const char hex[16] = "0123456789ABCDEF";
|
||
|
||
will trigger a warning like
|
||
|
||
$ gcc -Wextra -c nonstring.c
|
||
nonstring.c: In function ‘hexit’:
|
||
nonstring.c:9:37: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (17 chars into 16 available) [-Wunterminated-string-initialization]
|
||
9 | static const char hex[16] = "0123456789ABCDEF";
|
||
| ^~~~~~~~~~~~~~~~~~
|
||
|
||
By adding NXT_NONSTRING like
|
||
|
||
static const char hex[16] NXT_NONSTRING = "0123456789ABCDEF";
|
||
|
||
we no longer get the warning.
|
||
|
||
Cc: Alejandro Colomar <alx@kernel.org>
|
||
Co-authored-by: Alejandro Colomar <alx@kernel.org>
|
||
Signed-off-by: Alejandro Colomar <alx@kernel.org>
|
||
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
||
---
|
||
src/nxt_http_parse.c | 2 +-
|
||
src/nxt_http_parse.h | 2 +-
|
||
src/nxt_sprintf.c | 4 ++--
|
||
src/nxt_string.c | 4 ++--
|
||
4 files changed, 6 insertions(+), 6 deletions(-)
|
||
|
||
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
|
||
index dd490e729..3ae4d41c9 100644
|
||
--- a/src/nxt_http_parse.c
|
||
+++ b/src/nxt_http_parse.c
|
||
@@ -516,7 +516,7 @@ nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos,
|
||
size_t len;
|
||
uint32_t hash;
|
||
|
||
- static const u_char normal[256] nxt_aligned(64) =
|
||
+ static const u_char normal[256] NXT_NONSTRING nxt_aligned(64) =
|
||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||
/* \s ! " # $ % & ' ( ) * + , . / : ; < = > ? */
|
||
"\0\1\0\1\1\1\1\1\0\0\1\1\0" "-" "\1\0" "0123456789" "\0\0\0\0\0\0"
|
||
diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h
|
||
index 9e2f6fabb..157dc47db 100644
|
||
--- a/src/nxt_http_parse.h
|
||
+++ b/src/nxt_http_parse.h
|
||
@@ -21,7 +21,7 @@ typedef struct nxt_http_fields_hash_s nxt_http_fields_hash_t;
|
||
|
||
|
||
typedef union {
|
||
- u_char str[8];
|
||
+ u_char str[8] NXT_NONSTRING;
|
||
uint64_t ui64;
|
||
|
||
struct {
|
||
diff --git a/src/nxt_sprintf.c b/src/nxt_sprintf.c
|
||
index 875f43a59..2e29e80ef 100644
|
||
--- a/src/nxt_sprintf.c
|
||
+++ b/src/nxt_sprintf.c
|
||
@@ -112,8 +112,8 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
|
||
nxt_sprintf_t spf;
|
||
nxt_file_name_t *fn;
|
||
|
||
- static const u_char hexadecimal[16] = "0123456789abcdef";
|
||
- static const u_char HEXADECIMAL[16] = "0123456789ABCDEF";
|
||
+ static const u_char hexadecimal[16] NXT_NONSTRING = "0123456789abcdef";
|
||
+ static const u_char HEXADECIMAL[16] NXT_NONSTRING = "0123456789ABCDEF";
|
||
static const u_char nan[] = "[nan]";
|
||
static const u_char null[] = "[null]";
|
||
static const u_char infinity[] = "[infinity]";
|
||
diff --git a/src/nxt_string.c b/src/nxt_string.c
|
||
index 1ca595a1c..a23ee058f 100644
|
||
--- a/src/nxt_string.c
|
||
+++ b/src/nxt_string.c
|
||
@@ -598,7 +598,7 @@ nxt_encode_uri(u_char *dst, u_char *src, size_t length)
|
||
u_char *end;
|
||
nxt_uint_t n;
|
||
|
||
- static const u_char hex[16] = "0123456789ABCDEF";
|
||
+ static const u_char hex[16] NXT_NONSTRING = "0123456789ABCDEF";
|
||
|
||
end = src + length;
|
||
|
||
@@ -644,7 +644,7 @@ nxt_encode_complex_uri(u_char *dst, u_char *src, size_t length)
|
||
u_char *reserved, *end, ch;
|
||
nxt_uint_t n;
|
||
|
||
- static const u_char hex[16] = "0123456789ABCDEF";
|
||
+ static const u_char hex[16] NXT_NONSTRING = "0123456789ABCDEF";
|
||
|
||
reserved = (u_char *) "?#\0";
|
||
|
||
diff --git a/src/test/nxt_http_parse_test.c b/src/test/nxt_http_parse_test.c
|
||
index 474b3f8d..2cab0dfa 100644
|
||
--- a/src/test/nxt_http_parse_test.c
|
||
+++ b/src/test/nxt_http_parse_test.c
|
||
@@ -12,7 +12,7 @@ typedef struct {
|
||
nxt_str_t method;
|
||
nxt_str_t target;
|
||
nxt_str_t args;
|
||
- u_char version[8];
|
||
+ u_char version[8] NXT_NONSTRING;
|
||
|
||
/* target with "/." */
|
||
unsigned complex_target:1;
|
||
diff --git a/src/test/nxt_utf8_file_name_test.c b/src/test/nxt_utf8_file_name_test.c
|
||
index 5723e19b..b77cd4ab 100644
|
||
--- a/src/test/nxt_utf8_file_name_test.c
|
||
+++ b/src/test/nxt_utf8_file_name_test.c
|
||
@@ -48,7 +48,7 @@ nxt_utf8_file_name_test(nxt_thread_t *thr)
|
||
nxt_file_t uc_file, lc_file;
|
||
const u_char *pp;
|
||
nxt_file_name_t uc_name[10], lc_name[10];
|
||
- static const u_char utf8[4] = "UTF8";
|
||
+ static const u_char utf8[4] NXT_NONSTRING = "UTF8";
|
||
|
||
nxt_thread_time_update(thr);
|
||
|