From e791e4532ee7261fe9fd1dc665157c04f1bd3733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 3 Jul 2015 10:56:34 +0200 Subject: [PATCH] common: use offsetof for QUEUE_DATA Silences the following runtime errors when compiling UBSan: ../src/unix/linux-core.c:181:9: runtime error: member access within null pointer of type 'uv__io_t' (aka 'struct uv__io_s') ../src/unix/process.c:67:15: runtime error: member access within null pointer of type 'uv_process_t' (aka 'struct uv_process_s') ../src/unix/process.c:91:15: runtime error: member access within null pointer of type 'uv_process_t' (aka 'struct uv_process_s') ... PR-URL: https://github.com/libuv/libuv/pull/422 Reviewed-By: Ben Noordhuis --- src/queue.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/queue.h b/src/queue.h index fe02b454..60c80000 100644 --- a/src/queue.h +++ b/src/queue.h @@ -16,6 +16,8 @@ #ifndef QUEUE_H_ #define QUEUE_H_ +#include + typedef void *QUEUE[2]; /* Private macros. */ @@ -26,7 +28,7 @@ typedef void *QUEUE[2]; /* Public macros. */ #define QUEUE_DATA(ptr, type, field) \ - ((type *) ((char *) (ptr) - ((char *) &((type *) 0)->field))) + ((type *) ((char *) (ptr) - offsetof(type, field))) #define QUEUE_FOREACH(q, h) \ for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q))