Skip to content

Instantly share code, notes, and snippets.

@xeioex
Created September 17, 2025 01:32
Show Gist options
  • Save xeioex/c7c03791ec62d800197aa2d8c21b9925 to your computer and use it in GitHub Desktop.
Save xeioex/c7c03791ec62d800197aa2d8c21b9925 to your computer and use it in GitHub Desktop.
commit f422b9f7f4b1a0d8a7f98a3b2702e87a997d7515
Author: Dmitry Volyntsev <[email protected]>
Date: Tue Sep 16 18:28:05 2025 -0700
Fixed build with gcc-15 and -O3.
build/src/njs_object.dep -MT build/src/njs_object.o \ src/njs_object.c
In file included from src/njs_main.h:18, from src/njs_object.c:8: In
function ‘njs_utf8_copy’, inlined from ‘njs_object_enumerate_string’ at
src/njs_object.c:769:21: src/njs_utf8.h:115:20: error: writing 1 byte
into a region of size 0 [-Werror=stringop-overflow=] 115 |
*dst++ = c; | ~~~~~~~^~~ src/njs_object.c: In function
‘njs_object_enumerate_string’: src/njs_object.c:719:24: note: at offset
4 into destination object ‘buf’ of size 4 719 | u_char
buf[4], *c; | ^~~ In function ‘njs_utf8_copy’,
inlined from ‘njs_object_enumerate_string’ at src/njs_object.c:769:21:
src/njs_utf8.h:115:20: error: writing 1 byte into a region of size 0
[-Werror=stringop-overflow=]
GCC-15 does not know that the loop in njs_utf8_copy() is bounded
because the input is a valid UTF-8 here.
diff --git a/src/njs_array.c b/src/njs_array.c
index bcf428e9..b8cb9f94 100644
--- a/src/njs_array.c
+++ b/src/njs_array.c
@@ -788,7 +788,6 @@ static njs_int_t
njs_array_prototype_slice_copy(njs_vm_t *vm, njs_value_t *this,
int64_t start, int64_t length, njs_value_t *retval)
{
- u_char *c, buf[4];
size_t size;
uint32_t n;
njs_int_t ret;
@@ -829,17 +828,15 @@ njs_array_prototype_slice_copy(njs_vm_t *vm, njs_value_t *this,
do {
value = &array->start[n++];
- c = buf;
- c = njs_utf8_copy(c, &src, end);
- size = c - buf;
+ size = njs_utf8_next(src, end) - src;
- ret = njs_string_new(vm, value, buf, size, 1);
+ ret = njs_string_new(vm, value, src, size, 1);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
- length--;
- } while (length != 0);
+ src += size;
+ } while (src != end);
} else if (njs_is_object(this)) {
diff --git a/src/njs_object.c b/src/njs_object.c
index 7f0b1822..26e8182b 100644
--- a/src/njs_object.c
+++ b/src/njs_object.c
@@ -715,7 +715,6 @@ static njs_int_t
njs_object_enumerate_string(njs_vm_t *vm, const njs_value_t *value,
njs_array_t *items, uint32_t flags)
{
- u_char buf[4], *c;
uint32_t i, len, size;
njs_int_t ret;
njs_value_t *item, *string;
@@ -763,17 +762,15 @@ njs_object_enumerate_string(njs_vm_t *vm, const njs_value_t *value,
end = src + str_prop.size;
do {
- c = buf;
+ size = njs_utf8_next(src, end) - src;
- c = njs_utf8_copy(c, &src, end);
- size = c - buf;
-
- ret = njs_string_new(vm, item, buf, size, 1);
+ ret = njs_string_new(vm, item, src, size, 1);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
item++;
+ src += size;
} while (src != end);
}
@@ -828,12 +825,9 @@ njs_object_enumerate_string(njs_vm_t *vm, const njs_value_t *value,
string = &entry->start[1];
- c = buf;
-
- c = njs_utf8_copy(c, &src, end);
- size = c - buf;
+ size = njs_utf8_next(src, end) - src;
- ret = njs_string_new(vm, string, buf, size, 1);
+ ret = njs_string_new(vm, string, src, size, 1);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
@@ -841,6 +835,7 @@ njs_object_enumerate_string(njs_vm_t *vm, const njs_value_t *value,
njs_set_array(item, entry);
item++;
+ src += size;
} while (src != end);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment