From 7d8504cf691325698a998cd55062156296185989 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 15 Jun 2013 13:37:07 +0200 Subject: [PATCH] queue: fix pointer truncation on LLP64 platforms QUEUE_DATA used to cast a pointer to long and back to pointer. This can corrupt pointers on systems where the long type isn't large enough to store pointer, like Windows x64. This commit fixes that. Fixes #835 --- src/queue.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/queue.h b/src/queue.h index 0a3783b9..2f5ab610 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) - ((long) &((type *) 0)->field))) + ((type *) ((char *) (ptr) - ((uintptr_t) &((type *) 0)->field))) #define QUEUE_FOREACH(q, h) \ for ((q) = (QUEUE *) (*(h))[0]; (q) != (h); (q) = (QUEUE *) (*(q))[0])