From 3925936969e993709c832731343ace3ff5e695d0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 10 May 2017 12:33:10 +1000 Subject: [PATCH] util: fix container_of() macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a bunch of warnings of the kind ../src/evdev.h:378:32: warning: variable 'f' is uninitialized when used here [-Wuninitialized] return container_of(dispatch, f, base); Just typecasting NULL means we can ignore sample but for the type. https://bugs.freedesktop.org/show_bug.cgi?id=100976 Signed-off-by: Peter Hutterer Reviewed-by: Armin Krezović Tested-by: Armin Krezović Reviewed-by: Eric Engestrom --- src/libinput-util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libinput-util.h b/src/libinput-util.h index a9a2b660..9ecded7e 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -87,7 +87,7 @@ bool list_empty(const struct list *list); #define container_of(ptr, sample, member) \ (__typeof__(sample))((char *)(ptr) - \ - ((char *)&(sample)->member - (char *)(sample))) + ((char *)&((typeof(sample))0)->member)) #define list_for_each(pos, head, member) \ for (pos = 0, pos = container_of((head)->next, pos, member); \