[Mesa-dev] [PATCH 2/5] util/list: fix member access within null pointer
Bartosz Tomczyk
bartosz.tomczyk86 at gmail.com
Tue Feb 7 18:34:20 UTC 2017
---
configure.ac | 3 +++
src/util/list.h | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/configure.ac b/configure.ac
index a6ceee95a3..87f635c1a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -415,6 +415,9 @@ AC_C_BIGENDIAN(
little_endian=no
)
+dnl Chek for typeof support
+AC_C_TYPEOF()
+
dnl Check for POWER8 Architecture
PWR8_CFLAGS="-mpower8-vector"
have_pwr8_intrinsics=no
diff --git a/src/util/list.h b/src/util/list.h
index 07eb9f3e6a..eaaac43fec 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -171,10 +171,19 @@ static inline void list_validate(struct list_head *list)
* 'sample' MUST be initialized, or else the result is undefined!
*/
#ifndef container_of
+#if HAVE_TYPEOF
+#define container_of_typed(ptr, type, member) ({ \
+ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#define container_of(ptr, sample, member) \
+ container_of_typed(ptr, __typeof__(*sample), member)
+#else
#define container_of(ptr, sample, member) \
(void *)((char *)(ptr) \
- ((char *)&(sample)->member - (char *)(sample)))
#endif
+#endif
#define list_first_entry(ptr, type, member) \
LIST_ENTRY(type, (ptr)->next, member)
--
2.11.1
More information about the mesa-dev
mailing list