From f995dfcc20b7e930029544dc70a7780509b8c028 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Apr 2015 23:50:05 +0200 Subject: [PATCH] Better fix for libtiff warnings covering 64 bit case too. This improves commit dd3cb24cc056a8b460acb2b525035a919c76ba6a by fixing not only the warning about casting int to a pointer, but also the (usually more serious but still harmless in this particular case) warnings about casting pointers to ints and doing it via the usual union cast instead of compiler- specific pragmas. --- src/tiff/libtiff/tif_unix.c | 45 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/tiff/libtiff/tif_unix.c b/src/tiff/libtiff/tif_unix.c index f2a4583dea..5ae1934103 100644 --- a/src/tiff/libtiff/tif_unix.c +++ b/src/tiff/libtiff/tif_unix.c @@ -54,53 +54,69 @@ #include "tiffiop.h" +typedef union fd_as_handle_union +{ + int fd; + thandle_t h; +} fd_as_handle_union_t; + static tmsize_t _tiffReadProc(thandle_t fd, void* buf, tmsize_t size) { + fd_as_handle_union_t fdh; size_t size_io = (size_t) size; if ((tmsize_t) size_io != size) { errno=EINVAL; return (tmsize_t) -1; } - return ((tmsize_t) read((int) fd, buf, size_io)); + fdh.h = fd; + return ((tmsize_t) read(fdh.fd, buf, size_io)); } static tmsize_t _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) { + fd_as_handle_union_t fdh; size_t size_io = (size_t) size; if ((tmsize_t) size_io != size) { errno=EINVAL; return (tmsize_t) -1; } - return ((tmsize_t) write((int) fd, buf, size_io)); + fdh.h = fd; + return ((tmsize_t) write(fdh.fd, buf, size_io)); } static uint64 _tiffSeekProc(thandle_t fd, uint64 off, int whence) { + fd_as_handle_union_t fdh; off_t off_io = (off_t) off; if ((uint64) off_io != off) { errno=EINVAL; return (uint64) -1; /* this is really gross */ } - return((uint64)lseek((int)fd,off_io,whence)); + fdh.h = fd; + return((uint64)lseek(fdh.fd,off_io,whence)); } static int _tiffCloseProc(thandle_t fd) { - return(close((int)fd)); + fd_as_handle_union_t fdh; + fdh.h = fd; + return(close(fdh.fd)); } static uint64 _tiffSizeProc(thandle_t fd) { + fd_as_handle_union_t fdh; + fdh.h = fd; struct stat sb; - if (fstat((int)fd,&sb)<0) + if (fstat(fdh.fd,&sb)<0) return(0); else return((uint64)sb.st_size); @@ -115,8 +131,10 @@ _tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) uint64 size64 = _tiffSizeProc(fd); tmsize_t sizem = (tmsize_t)size64; if ((uint64)sizem==size64) { + fd_as_handle_union_t fdh; + fdh.h = fd; *pbase = (void*) - mmap(0, (size_t)sizem, PROT_READ, MAP_SHARED, (int) fd, 0); + mmap(0, (size_t)sizem, PROT_READ, MAP_SHARED, fdh.fd, 0); if (*pbase != (void*) -1) { *psize = (tmsize_t)sizem; return (1); @@ -154,22 +172,13 @@ TIFFFdOpen(int fd, const char* name, const char* mode) { TIFF* tif; - /* Avoid warning about casting int fd to larger thandle_t in 64 bits. */ -#ifdef __clang__ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" -#endif - + fd_as_handle_union_t fdh; + fdh.fd = fd; tif = TIFFClientOpen(name, mode, - (thandle_t) fd, + fdh.h, _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); - -#ifdef __clang__ - #pragma clang diagnostic pop -#endif - if (tif) tif->tif_fd = fd; return (tif);