From d422b954be178afca1abeded9054ee6e39272904 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Mon, 9 Oct 2017 13:37:42 +0200 Subject: Fix pointer/int cast warnings on 64-bit Windows On 64-bit Windows, `long` is 32 bits wide and can't hold a pointer. Switch to ptrdiff_t instead which should be the same size as a pointer on every somewhat sane platform without requiring C99 types like intptr_t. Fixes bug 788312. Thanks to J. Peter Mugaas for the report and initial patch. --- xmlIO.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'xmlIO.c') diff --git a/xmlIO.c b/xmlIO.c index 6891ff9a..5902f627 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -12,6 +12,7 @@ #include "libxml.h" #include +#include #ifdef HAVE_ERRNO_H #include #endif @@ -826,7 +827,7 @@ static int xmlFdRead (void * context, char * buffer, int len) { int ret; - ret = read((int) (long) context, &buffer[0], len); + ret = read((int) (ptrdiff_t) context, &buffer[0], len); if (ret < 0) xmlIOErr(0, "read()"); return(ret); } @@ -847,7 +848,7 @@ xmlFdWrite (void * context, const char * buffer, int len) { int ret = 0; if (len > 0) { - ret = write((int) (long) context, &buffer[0], len); + ret = write((int) (ptrdiff_t) context, &buffer[0], len); if (ret < 0) xmlIOErr(0, "write()"); } return(ret); @@ -865,7 +866,7 @@ xmlFdWrite (void * context, const char * buffer, int len) { static int xmlFdClose (void * context) { int ret; - ret = close((int) (long) context); + ret = close((int) (ptrdiff_t) context); if (ret < 0) xmlIOErr(0, "close()"); return(ret); } @@ -3008,7 +3009,7 @@ xmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc) { ret = xmlAllocParserInputBuffer(enc); if (ret != NULL) { - ret->context = (void *) (long) fd; + ret->context = (void *) (ptrdiff_t) fd; ret->readcallback = xmlFdRead; ret->closecallback = xmlFdClose; } @@ -3114,7 +3115,7 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) { ret = xmlAllocOutputBufferInternal(encoder); if (ret != NULL) { - ret->context = (void *) (long) fd; + ret->context = (void *) (ptrdiff_t) fd; ret->writecallback = xmlFdWrite; ret->closecallback = NULL; } -- cgit v1.2.1