[Mesa-dev] [PATCH 2/5] util/list: fix member access within null pointer
Nicolai Hähnle
nhaehnle at gmail.com
Fri Feb 10 09:26:34 UTC 2017
On 07.02.2017 19:34, Bartosz Tomczyk wrote:
> ---
> 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) );})
I believe this syntax is a GCC extension. Do all compilers with typeof
also support that extension? This is something to be checked especially
on Windows. Apart from that, the change looks good to me.
Nicolai
> +
> +#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)
>
More information about the mesa-dev
mailing list