Skip to content

Commit d9c2fd7

Browse files
Tag various character arrays with NXT_NONSTRING
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 <[email protected]> Co-authored-by: Alejandro Colomar <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]> Signed-off-by: Andrew Clayton <[email protected]>
1 parent 764ad73 commit d9c2fd7

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/nxt_http_parse.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos,
516516
size_t len;
517517
uint32_t hash;
518518

519-
static const u_char normal[256] nxt_aligned(64) =
519+
static const u_char normal[256] NXT_NONSTRING nxt_aligned(64) =
520520
"\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"
521521
/* \s ! " # $ % & ' ( ) * + , . / : ; < = > ? */
522522
"\0\1\0\1\1\1\1\1\0\0\1\1\0" "-" "\1\0" "0123456789" "\0\0\0\0\0\0"

src/nxt_http_parse.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct nxt_http_fields_hash_s nxt_http_fields_hash_t;
2121

2222

2323
typedef union {
24-
u_char str[8];
24+
u_char str[8] NXT_NONSTRING;
2525
uint64_t ui64;
2626

2727
struct {

src/nxt_sprintf.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
112112
nxt_sprintf_t spf;
113113
nxt_file_name_t *fn;
114114

115-
static const u_char hexadecimal[16] = "0123456789abcdef";
116-
static const u_char HEXADECIMAL[16] = "0123456789ABCDEF";
115+
static const u_char hexadecimal[16] NXT_NONSTRING = "0123456789abcdef";
116+
static const u_char HEXADECIMAL[16] NXT_NONSTRING = "0123456789ABCDEF";
117117
static const u_char nan[] = "[nan]";
118118
static const u_char null[] = "[null]";
119119
static const u_char infinity[] = "[infinity]";

src/nxt_string.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ nxt_encode_uri(u_char *dst, u_char *src, size_t length)
598598
u_char *end;
599599
nxt_uint_t n;
600600

601-
static const u_char hex[16] = "0123456789ABCDEF";
601+
static const u_char hex[16] NXT_NONSTRING = "0123456789ABCDEF";
602602

603603
end = src + length;
604604

@@ -644,7 +644,7 @@ nxt_encode_complex_uri(u_char *dst, u_char *src, size_t length)
644644
u_char *reserved, *end, ch;
645645
nxt_uint_t n;
646646

647-
static const u_char hex[16] = "0123456789ABCDEF";
647+
static const u_char hex[16] NXT_NONSTRING = "0123456789ABCDEF";
648648

649649
reserved = (u_char *) "?#\0";
650650

0 commit comments

Comments
 (0)