trace-cmd: Use builtin for offset_of
PATCH 1/1 trace-cmd: Use builtin for offset_of
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/[email protected]/
Signed-off-by Ian Rogers <[email protected]>
--- tracecmd/include/list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tracecmd/include/list.h +1 -1
@@ -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 {
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Steven Rostedt
AppliedQuoted 4 lines · On Tue, 8 Mar 2022 20:38:15 -0800 Ian Rogers <[email protected]> wrote:
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/[email protected]/
Applied, thanks Ian!
-- Steve
Quoted 19 lines
Signed-off-by Ian Rogers <[email protected]>--- tracecmd/include/list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tracecmd/include/list.h +1
-1@@ -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 {