Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nxt_cpymem() is basically mempcpy(3) Like mempcpy() nxt_cpymem() returns a void *. nxt_cpymem() is implemented as a wrapper around memcpy(3), however before returning the new pointer value we cast the return of memcpy(3) to a u_char *, then add the length parameter to it. I guess this was done to support compilers that do not support arithmetic on void pointers as the C standard forbids it. However since we removed support for compilers other than GCC and Clang (ending in commit 9cd1113 ("Remove support for Sun's Sun Studio/SunPro C compiler")) this is no longer an issue as both GCC and Clang support arithmetic on void pointers (without the -pedantic option) by treating the size of a void as 1. While removing the unnecessary casting in this case doesn't necessarily improve type-safety (as we're dealing with void *'s in and out), it does just make the code that little more readable. Oh and for interest we have actually already been relying on this extension src/nxt_array.c:143:40: warning: arithmetic on a pointer to void is a GNU extension [-Wgnu-pointer-arith] 143 | nxt_memcpy(data, src->elts + (i * size), size); | ~~~~~~~~~ ^ src/nxt_string.h:45:24: note: expanded from macro 'nxt_memcpy' 45 | (void) memcpy(dst, src, length) | ^~~ which was introduced in e2b53e1 ("Added "rootfs" feature.") back in 2020. Link: <https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html> Link: <https://clang.llvm.org/docs/LanguageExtensions.html#introduction> Signed-off-by: Andrew Clayton <[email protected]>
- Loading branch information