diff options
author | Andrew Clayton <andrew@digital-domain.net> | 2022-06-14 00:53:22 +0100 |
---|---|---|
committer | Andrew Clayton <andrew@digital-domain.net> | 2022-06-15 21:14:02 +0100 |
commit | 82f7d929bc242061be52d1d6a6f1a926a16da62f (patch) | |
tree | 0832898ed1288467fc3dd71045e4bdcf86ba029e | |
parent | 6a8081d71e805b12d0f7fd32ce72d60babadfc85 (diff) | |
download | unit-82f7d929bc242061be52d1d6a6f1a926a16da62f.tar.gz unit-82f7d929bc242061be52d1d6a6f1a926a16da62f.tar.bz2 |
Array: avoided void pointer arithmetic in nxt_array_copy().archive/arithOperationsOnVoidPointer
As was pointed out by the cppcheck[0] static code analysis utility we
were doing void pointer arithmetic on src->elts which is technically
undefined behaviour.
While GCC allows this by treating the size of void as 1[1]. Same with
Clang. Other compilers I'm not sure about, so lets just be safe and cast
src->nelts to (char *) where sizeof(char) is guaranteed to be 1.
[0]: https://cppcheck.sourceforge.io/
[1]: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html
-rw-r--r-- | src/nxt_array.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/nxt_array.c b/src/nxt_array.c index 1e13c22a..0a7945ec 100644 --- a/src/nxt_array.c +++ b/src/nxt_array.c @@ -140,7 +140,7 @@ nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst, nxt_array_t *src) return NULL; } - nxt_memcpy(data, src->elts + (i * size), size); + nxt_memcpy(data, (char *) src->elts + (i * size), size); } } |