From d3b46cca7b208b98fcd090043f8b4af4dd204de1 Mon Sep 17 00:00:00 2001 From: Ben Kallus Date: Sun, 20 Jul 2025 12:48:07 -0400 Subject: [PATCH] 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. --- include/haproxy/compiler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- 2.47.2