]> git.kaiwu.me - njs.git/commitdiff
Fixed ‘length’ may be used uninitialized in Array.prototype.pop().
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 21 Jun 2024 00:26:14 +0000 (17:26 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Sat, 29 Jun 2024 02:52:19 +0000 (19:52 -0700)
When building by GCC with -O3 and -flto flags the following
warning was reported:
src/njs_array.c: In function ‘njs_array_prototype_pop’:
src/njs_array.c:1009:8: error: ‘length’ may be used uninitialized in
this function [-Werror=maybe-uninitialized]
1009 | if (length == 0) {
     |     ^

Returning a specific code in njs_value_to_number() helps GCC
to infer that there are only 2 return values are possible and
both of them are handled.

src/njs_value_conversion.h

index f5a0e6767ea9daed393ab01898c535f7efaaa2bf..24483aa27276bfe3ce7714ec5f88f31d8323b97c 100644 (file)
@@ -17,7 +17,7 @@ njs_value_to_number(njs_vm_t *vm, njs_value_t *value, double *dst)
     if (njs_slow_path(!njs_is_primitive(value))) {
         ret = njs_value_to_primitive(vm, &primitive, value, 0);
         if (njs_slow_path(ret != NJS_OK)) {
-            return ret;
+            return NJS_ERROR;
         }
 
         value = &primitive;