From 82f7d929bc242061be52d1d6a6f1a926a16da62f Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Tue, 14 Jun 2022 00:53:22 +0100 Subject: Array: avoided void pointer arithmetic in nxt_array_copy(). 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 --- src/nxt_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nxt_array.c') 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); } } -- cgit