From 6caa5e92c195253fe7a6ad35e1b36bee10597e1e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Jul 2015 03:28:07 +0200 Subject: [PATCH] Fix warnings about pointer/int casts in Win32 part of libtiff too. Do the same thing for tif_win32.c as f995dfcc20b7e930029544dc70a7780509b8c028 did for tif_unix.c, i.e. use a union for casting between HANDLEs and ints to avoid compiler warnings which were given for the explicit casts before. --- src/tiff/libtiff/tif_unix.c | 6 ------ src/tiff/libtiff/tif_win32.c | 24 +++++++++++++----------- src/tiff/libtiff/tiffiop.h | 11 +++++++++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/tiff/libtiff/tif_unix.c b/src/tiff/libtiff/tif_unix.c index 5ae1934103..1db40cdfd0 100644 --- a/src/tiff/libtiff/tif_unix.c +++ b/src/tiff/libtiff/tif_unix.c @@ -54,12 +54,6 @@ #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) { diff --git a/src/tiff/libtiff/tif_win32.c b/src/tiff/libtiff/tif_win32.c index b64dd8d5cf..479860c8d0 100644 --- a/src/tiff/libtiff/tif_win32.c +++ b/src/tiff/libtiff/tif_win32.c @@ -210,6 +210,8 @@ TIFFFdOpen(int ifd, const char* name, const char* mode) int fSuppressMap; int m; fSuppressMap=0; + fd_as_handle_union_t fdh; + fdh.fd = ifd; for (m=0; mode[m]!=0; m++) { if (mode[m]=='u') @@ -218,7 +220,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode) break; } } - tif = TIFFClientOpen(name, mode, (thandle_t)ifd, + tif = TIFFClientOpen(name, mode, fdh.h, _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, fSuppressMap ? _tiffDummyMapProc : _tiffMapProc, @@ -237,7 +239,7 @@ TIFF* TIFFOpen(const char* name, const char* mode) { static const char module[] = "TIFFOpen"; - thandle_t fd; + fd_as_handle_union_t fdh; int m; DWORD dwMode; TIFF* tif; @@ -253,19 +255,19 @@ TIFFOpen(const char* name, const char* mode) default: return ((TIFF*)0); } - fd = (thandle_t)CreateFileA(name, + fdh.h = CreateFileA(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, NULL); - if (fd == INVALID_HANDLE_VALUE) { + if (fdh.h == INVALID_HANDLE_VALUE) { TIFFErrorExt(0, module, "%s: Cannot open", name); return ((TIFF *)0); } - tif = TIFFFdOpen((int)fd, name, mode); + tif = TIFFFdOpen(fdh.fd, name, mode); if(!tif) - CloseHandle(fd); + CloseHandle(fdh.h); return tif; } @@ -276,7 +278,7 @@ TIFF* TIFFOpenW(const wchar_t* name, const char* mode) { static const char module[] = "TIFFOpenW"; - thandle_t fd; + fd_as_handle_union_t fdh; int m; DWORD dwMode; int mbsize; @@ -294,12 +296,12 @@ TIFFOpenW(const wchar_t* name, const char* mode) default: return ((TIFF*)0); } - fd = (thandle_t)CreateFileW(name, + fdh.h = CreateFileW(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, NULL); - if (fd == INVALID_HANDLE_VALUE) { + if (fdh.h == INVALID_HANDLE_VALUE) { TIFFErrorExt(0, module, "%S: Cannot open", name); return ((TIFF *)0); } @@ -318,10 +320,10 @@ TIFFOpenW(const wchar_t* name, const char* mode) NULL, NULL); } - tif = TIFFFdOpen((int)fd, + tif = TIFFFdOpen(fdh.fd, (mbname != NULL) ? mbname : "", mode); if(!tif) - CloseHandle(fd); + CloseHandle(fdh.h); _TIFFfree(mbname); diff --git a/src/tiff/libtiff/tiffiop.h b/src/tiff/libtiff/tiffiop.h index 3d9551a80b..748ed4598a 100644 --- a/src/tiff/libtiff/tiffiop.h +++ b/src/tiff/libtiff/tiffiop.h @@ -77,6 +77,17 @@ typedef struct client_info { char *name; } TIFFClientInfoLink; +/* + * Union allowing to cast between the OS-specific handles and integer file + * descriptors without triggering compiler warnings, even if their types are + * not the same. + */ +typedef union fd_as_handle_union +{ + int fd; + thandle_t h; +} fd_as_handle_union_t; + /* * Typedefs for ``method pointers'' used internally. * these are depriciated and provided only for backwards compatibility