From: Ben Kallus Date: Sun, 20 Jul 2025 16:48:07 +0000 (-0400) Subject: CLEANUP: compiler: prefer char * over void * for pointer arithmetic X-Git-Tag: v3.3-dev4~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3b46cca7b208b98fcd090043f8b4af4dd204de1;p=thirdparty%2Fhaproxy.git CLEANUP: compiler: prefer char * over void * for pointer arithmetic This patch changes two instances of pointer arithmetic on void * to use char * instead, to avoid UB. This is essentially to please UB analyzers, though. --- diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index 80d9be772..01a1a62e7 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -350,7 +350,7 @@ * which has its member stored at address . */ #ifndef container_of -#define container_of(ptr, type, name) ((type *)(((void *)(ptr)) - ((long)&((type *)0)->name))) +#define container_of(ptr, type, name) ((type *)(((char *)(ptr)) - ((long)&((type *)0)->name))) #endif /* returns a pointer to the structure of type which has its member @@ -359,7 +359,7 @@ #ifndef container_of_safe #define container_of_safe(ptr, type, name) \ ({ void *__p = (ptr); \ - __p ? (type *)(__p - ((long)&((type *)0)->name)) : (type *)0; \ + __p ? (type *)((char *)__p - ((long)&((type *)0)->name)) : (type *)0; \ }) #endif