[PATCH libinput 2/5] util: fix container_of() macro

Peter Hutterer peter.hutterer at who-t.net
Wed May 10 03:47:57 UTC 2017


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 <peter.hutterer at who-t.net>
---
 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);	\
-- 
2.12.2



More information about the wayland-devel mailing list