Better fix for libtiff warnings covering 64 bit case too.

This improves commit dd3cb24cc0 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.
This commit is contained in:
Vadim Zeitlin
2015-04-12 23:50:05 +02:00
parent e2f43574f4
commit f995dfcc20

View File

@@ -54,53 +54,69 @@
#include "tiffiop.h" #include "tiffiop.h"
typedef union fd_as_handle_union
{
int fd;
thandle_t h;
} fd_as_handle_union_t;
static tmsize_t static tmsize_t
_tiffReadProc(thandle_t fd, void* buf, tmsize_t size) _tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
{ {
fd_as_handle_union_t fdh;
size_t size_io = (size_t) size; size_t size_io = (size_t) size;
if ((tmsize_t) size_io != size) if ((tmsize_t) size_io != size)
{ {
errno=EINVAL; errno=EINVAL;
return (tmsize_t) -1; 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 static tmsize_t
_tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size)
{ {
fd_as_handle_union_t fdh;
size_t size_io = (size_t) size; size_t size_io = (size_t) size;
if ((tmsize_t) size_io != size) if ((tmsize_t) size_io != size)
{ {
errno=EINVAL; errno=EINVAL;
return (tmsize_t) -1; 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 static uint64
_tiffSeekProc(thandle_t fd, uint64 off, int whence) _tiffSeekProc(thandle_t fd, uint64 off, int whence)
{ {
fd_as_handle_union_t fdh;
off_t off_io = (off_t) off; off_t off_io = (off_t) off;
if ((uint64) off_io != off) if ((uint64) off_io != off)
{ {
errno=EINVAL; errno=EINVAL;
return (uint64) -1; /* this is really gross */ 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 static int
_tiffCloseProc(thandle_t fd) _tiffCloseProc(thandle_t fd)
{ {
return(close((int)fd)); fd_as_handle_union_t fdh;
fdh.h = fd;
return(close(fdh.fd));
} }
static uint64 static uint64
_tiffSizeProc(thandle_t fd) _tiffSizeProc(thandle_t fd)
{ {
fd_as_handle_union_t fdh;
fdh.h = fd;
struct stat sb; struct stat sb;
if (fstat((int)fd,&sb)<0) if (fstat(fdh.fd,&sb)<0)
return(0); return(0);
else else
return((uint64)sb.st_size); return((uint64)sb.st_size);
@@ -115,8 +131,10 @@ _tiffMapProc(thandle_t fd, void** pbase, toff_t* psize)
uint64 size64 = _tiffSizeProc(fd); uint64 size64 = _tiffSizeProc(fd);
tmsize_t sizem = (tmsize_t)size64; tmsize_t sizem = (tmsize_t)size64;
if ((uint64)sizem==size64) { if ((uint64)sizem==size64) {
fd_as_handle_union_t fdh;
fdh.h = fd;
*pbase = (void*) *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) { if (*pbase != (void*) -1) {
*psize = (tmsize_t)sizem; *psize = (tmsize_t)sizem;
return (1); return (1);
@@ -154,22 +172,13 @@ TIFFFdOpen(int fd, const char* name, const char* mode)
{ {
TIFF* tif; TIFF* tif;
/* Avoid warning about casting int fd to larger thandle_t in 64 bits. */ fd_as_handle_union_t fdh;
#ifdef __clang__ fdh.fd = fd;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"
#endif
tif = TIFFClientOpen(name, mode, tif = TIFFClientOpen(name, mode,
(thandle_t) fd, fdh.h,
_tiffReadProc, _tiffWriteProc, _tiffReadProc, _tiffWriteProc,
_tiffSeekProc, _tiffCloseProc, _tiffSizeProc, _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
_tiffMapProc, _tiffUnmapProc); _tiffMapProc, _tiffUnmapProc);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
if (tif) if (tif)
tif->tif_fd = fd; tif->tif_fd = fd;
return (tif); return (tif);