Skip to content

Commit d7db165

Browse files
committed
Tagged various character arrays with NJS_NONSTRING.
In njs we have a number of character arrays which are intentionally not NUL terminated. With GCC 15 this static const u_char hex[16] = "0123456789ABCDEF"; will trigger a warning (which we treat as an error) like src/njs_string.h: In function ‘njs_string_encode’: src/njs_string.h:212:36: error: initializer-string for array of ‘unsigned char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (17 chars into 16 available) [-Werror=unterminated-string-initialization] 212 | static const u_char hex[16] = "0123456789ABCDEF"; | ^~~~~~~~~~~~~~~~~~ By adding NJS_NONSTRING like static const u_char hex[16] NJS_NONSTRING = "0123456789ABCDEF"; we no longer get the warning. Closes: #857 Signed-off-by: Andrew Clayton <[email protected]>
1 parent 0986e28 commit d7db165

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

external/qjs_query_string_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ qjs_string_encode(const uint32_t *escape, size_t size, const u_char *src,
537537
u_char *dst)
538538
{
539539
uint8_t byte;
540-
static const u_char hex[16] = "0123456789ABCDEF";
540+
static const u_char hex[16] NJS_NONSTRING = "0123456789ABCDEF";
541541

542542
do {
543543
byte = *src++;

src/njs_sprintf.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ njs_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
9595
njs_bool_t sign;
9696
njs_sprintf_t spf;
9797

98-
static const u_char hexadecimal[16] = "0123456789abcdef";
99-
static const u_char HEXADECIMAL[16] = "0123456789ABCDEF";
98+
static const u_char hexadecimal[16] NJS_NONSTRING = "0123456789abcdef";
99+
static const u_char HEXADECIMAL[16] NJS_NONSTRING = "0123456789ABCDEF";
100100
static const u_char nan[] = "[nan]";
101101
static const u_char infinity[] = "[infinity]";
102102

src/njs_string.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ njs_encode_hex(njs_str_t *dst, const njs_str_t *src)
309309
size_t i, len;
310310
const u_char *start;
311311

312-
static const u_char hex[16] = "0123456789abcdef";
312+
static const u_char hex[16] NJS_NONSTRING = "0123456789abcdef";
313313

314314
len = src->length;
315315
start = src->start;

src/njs_string.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ njs_string_encode(const uint32_t *escape, size_t size, const u_char *src,
209209
u_char *dst)
210210
{
211211
uint8_t byte;
212-
static const u_char hex[16] = "0123456789ABCDEF";
212+
static const u_char hex[16] NJS_NONSTRING = "0123456789ABCDEF";
213213

214214
do {
215215
byte = *src++;

src/qjs_buffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ qjs_hex_encode(JSContext *ctx, const njs_str_t *src, njs_str_t *dst)
23542354
size_t i, len;
23552355
const u_char *start;
23562356

2357-
static const u_char hex[16] = "0123456789abcdef";
2357+
static const u_char hex[16] NJS_NONSTRING = "0123456789abcdef";
23582358

23592359
len = src->length;
23602360
start = src->start;

0 commit comments

Comments
 (0)