Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
queue: fix pointer truncation on LLP64 platforms
Browse files Browse the repository at this point in the history
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 a pointer, like Windows x64. This commit fixes that.
  • Loading branch information
piscisaureus committed Jun 19, 2013
1 parent 7373c4d commit 6952255
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/queue.h
Expand Up @@ -16,6 +16,9 @@
#ifndef QUEUE_H_
#define QUEUE_H_

/* Including libuv ensures that uintptr_t is defined. */
#include <uv.h>

typedef void *QUEUE[2];

/* Private macros. */
Expand All @@ -26,7 +29,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])
Expand Down

0 comments on commit 6952255

Please sign in to comment.