[PATCH 3/3] include: Define LIST_ENTRY using offsetof

Amine Khaldi amine.khaldi at reactos.org
Mon Dec 10 12:44:00 CST 2012


This prevents the undefined behavior (null pointer dereference)
diagnostics (clang with ubsan checks for example).

---
 include/wine/list.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/wine/list.h b/include/wine/list.h
index 9712603..a66f445 100644
--- a/include/wine/list.h
+++ b/include/wine/list.h
@@ -226,7 +226,13 @@ static inline void list_move_head( struct list
*dst, struct list *src )
 
 /* get pointer to object containing list element */
 #undef LIST_ENTRY
+#if defined(__GNUC__) || defined(__clang__)
+#include <stddef.h>
+#define LIST_ENTRY(elem, type, field) \
+    ((type *)((char *)(elem) - offsetof(type, field)))
+#else
 #define LIST_ENTRY(elem, type, field) \
     ((type *)((char *)(elem) - (size_t)(&((type *)0)->field)))
+#endif
 
 #endif  /* __WINE_SERVER_LIST_H */
--
1.8.0




More information about the wine-patches mailing list