]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: compiler: prefer char * over void * for pointer arithmetic
authorBen Kallus <benjamin.p.kallus.gr@dartmouth.edu>
Sun, 20 Jul 2025 16:48:07 +0000 (12:48 -0400)
committerWilly Tarreau <w@1wt.eu>
Fri, 25 Jul 2025 15:54:32 +0000 (17:54 +0200)
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.

include/haproxy/compiler.h

index 80d9be77254ae5cf2294783315053c2d6e681481..01a1a62e7f7597ccb4f0decbed5e017125b689d1 100644 (file)
  * <type> which has its member <name> stored at address <ptr>.
  */
 #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 <type> which has its member <name>
 #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