From: Theodore Ts'o Date: Wed, 26 Feb 2025 02:51:43 +0000 (-0500) Subject: blkid: use offsetof() to avoid UBSAN warnings X-Git-Tag: v1.47.3-rc1~120 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6137323c883db5fe9c840b09f94cb1f1bfda599c;p=thirdparty%2Fe2fsprogs.git 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 --- diff --git a/lib/blkid/list.h b/lib/blkid/list.h index eb1c513f..a73dd83e 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