From fd2e9f820005d63769a6662c276b1f52a72ed041 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Wed, 1 Apr 2026 17:07:27 +0200 Subject: tools/nolibc: use __builtin_offsetof() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current custom implementation of offsetof() fails UBSAN: runtime error: member access within null pointer of type 'struct ...' This means that all its users, including container_of(), free() and realloc(), fail. Use __builtin_offsetof() instead which does not have this issue and has been available since GCC 4 and clang 3. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau Link: https://patch.msgid.link/20260401-nolibc-asprintf-v1-1-46292313439f@weissschuh.net --- tools/include/nolibc/stddef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/include/nolibc') diff --git a/tools/include/nolibc/stddef.h b/tools/include/nolibc/stddef.h index ecbd13eab1f5..a3976341afdd 100644 --- a/tools/include/nolibc/stddef.h +++ b/tools/include/nolibc/stddef.h @@ -18,7 +18,7 @@ #endif #ifndef offsetof -#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) +#define offsetof(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD) #endif #endif /* _NOLIBC_STDDEF_H */ -- cgit v1.2.3