[PATCH] trace-cmd: Use builtin for offset_of

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Arithmetic on null pointers is undefined behavior, spotted by C compiler
sanitizers such as with clang. The builtin offset of is available in all
recent compilers, so unconditionally use it as discussed for libbpf in:
https://lore.kernel.org/all/a0a26308-a1d7-a57c-727c-000652a5d246@xxxxxx/

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
 tracecmd/include/list.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tracecmd/include/list.h b/tracecmd/include/list.h
index cf9dd47e..fa0de6df 100644
--- a/tracecmd/include/list.h
+++ b/tracecmd/include/list.h
@@ -6,7 +6,7 @@
 #ifndef __LIST_H
 #define __LIST_H
 
-#define offset_of(type, field)		(long)(&((type *)0)->field)
+#define offset_of(type, field)		__builtin_offsetof(type, field)
 #define container_of(p, type, field)	(type *)((long)p - offset_of(type, field))
 
 struct list_head {
-- 
2.35.1.616.g0bdcbb4464-goog




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux