From 6137323c883db5fe9c840b09f94cb1f1bfda599c Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 25 Feb 2025 21:51:43 -0500 Subject: [PATCH] blkid: use offsetof() to avoid UBSAN warnings Newer versions of clang complain about "member access within null pointer" when using the construct: (unsigned long)(intptr_t)(&((type *)0)->member) So use offsetof(type, member) instead. Signed-off-by: Theodore Ts'o --- lib/blkid/list.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/blkid/list.h b/lib/blkid/list.h index eb1c513f6..a73dd83eb 100644 --- a/lib/blkid/list.h +++ b/lib/blkid/list.h @@ -12,6 +12,7 @@ extern "C" { #include #endif #endif +#include #ifdef __GNUC__ #define _INLINE_ static __inline__ @@ -154,7 +155,7 @@ _INLINE_ void list_splice(struct list_head *list, struct list_head *head) * @member: the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(intptr_t)(&((type *)0)->member))) + ((type *)((char *)(ptr) - offsetof(type, member))) /** * list_for_each - iterate over elements in a list -- 2.47.2