]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
blkid: use offsetof() to avoid UBSAN warnings
authorTheodore Ts'o <tytso@mit.edu>
Wed, 26 Feb 2025 02:51:43 +0000 (21:51 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 26 Feb 2025 03:04:20 +0000 (22:04 -0500)
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 <tytso@mit.edu>
lib/blkid/list.h

index eb1c513f60ba1f348de702db0eeb6c57a94bf94b..a73dd83ebee9d5eac108cf80552a0c8e59be3706 100644 (file)
@@ -12,6 +12,7 @@ extern "C" {
 #include <stdint.h>
 #endif
 #endif
+#include <stddef.h>
 
 #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