Revert "Fix warnings about pointer/int casts in Win32 part of libtiff too."

This reverts commit 6caa5e92c1 because it fixed
a warning during compilation but broke the behaviour of TIFFFdOpen() during
run-time: initializing the union via its int component didn't clear the high
DWORD of the 64 bit thandle_t value, resulting in a wrong value being used.

Closes #17286.
This commit is contained in:
Vadim Zeitlin
2015-12-26 19:34:06 +01:00
parent 537fcac633
commit bad2538697
3 changed files with 17 additions and 24 deletions

View File

@@ -54,6 +54,12 @@
#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)
{ {

View File

@@ -209,9 +209,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode)
TIFF* tif; TIFF* tif;
int fSuppressMap; int fSuppressMap;
int m; int m;
fd_as_handle_union_t fdh;
fSuppressMap=0; fSuppressMap=0;
fdh.fd = ifd;
for (m=0; mode[m]!=0; m++) for (m=0; mode[m]!=0; m++)
{ {
if (mode[m]=='u') if (mode[m]=='u')
@@ -220,7 +218,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode)
break; break;
} }
} }
tif = TIFFClientOpen(name, mode, fdh.h, tif = TIFFClientOpen(name, mode, (thandle_t)ifd,
_tiffReadProc, _tiffWriteProc, _tiffReadProc, _tiffWriteProc,
_tiffSeekProc, _tiffCloseProc, _tiffSizeProc, _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
fSuppressMap ? _tiffDummyMapProc : _tiffMapProc, fSuppressMap ? _tiffDummyMapProc : _tiffMapProc,
@@ -239,7 +237,7 @@ TIFF*
TIFFOpen(const char* name, const char* mode) TIFFOpen(const char* name, const char* mode)
{ {
static const char module[] = "TIFFOpen"; static const char module[] = "TIFFOpen";
fd_as_handle_union_t fdh; thandle_t fd;
int m; int m;
DWORD dwMode; DWORD dwMode;
TIFF* tif; TIFF* tif;
@@ -255,19 +253,19 @@ TIFFOpen(const char* name, const char* mode)
default: return ((TIFF*)0); default: return ((TIFF*)0);
} }
fdh.h = CreateFileA(name, fd = (thandle_t)CreateFileA(name,
(m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE),
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode,
(m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL,
NULL); NULL);
if (fdh.h == INVALID_HANDLE_VALUE) { if (fd == INVALID_HANDLE_VALUE) {
TIFFErrorExt(0, module, "%s: Cannot open", name); TIFFErrorExt(0, module, "%s: Cannot open", name);
return ((TIFF *)0); return ((TIFF *)0);
} }
tif = TIFFFdOpen(fdh.fd, name, mode); tif = TIFFFdOpen((int)fd, name, mode);
if(!tif) if(!tif)
CloseHandle(fdh.h); CloseHandle(fd);
return tif; return tif;
} }
@@ -278,7 +276,7 @@ TIFF*
TIFFOpenW(const wchar_t* name, const char* mode) TIFFOpenW(const wchar_t* name, const char* mode)
{ {
static const char module[] = "TIFFOpenW"; static const char module[] = "TIFFOpenW";
fd_as_handle_union_t fdh; thandle_t fd;
int m; int m;
DWORD dwMode; DWORD dwMode;
int mbsize; int mbsize;
@@ -296,12 +294,12 @@ TIFFOpenW(const wchar_t* name, const char* mode)
default: return ((TIFF*)0); default: return ((TIFF*)0);
} }
fdh.h = CreateFileW(name, fd = (thandle_t)CreateFileW(name,
(m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE),
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode,
(m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL,
NULL); NULL);
if (fdh.h == INVALID_HANDLE_VALUE) { if (fd == INVALID_HANDLE_VALUE) {
TIFFErrorExt(0, module, "%S: Cannot open", name); TIFFErrorExt(0, module, "%S: Cannot open", name);
return ((TIFF *)0); return ((TIFF *)0);
} }
@@ -320,10 +318,10 @@ TIFFOpenW(const wchar_t* name, const char* mode)
NULL, NULL); NULL, NULL);
} }
tif = TIFFFdOpen(fdh.fd, tif = TIFFFdOpen((int)fd,
(mbname != NULL) ? mbname : "<unknown>", mode); (mbname != NULL) ? mbname : "<unknown>", mode);
if(!tif) if(!tif)
CloseHandle(fdh.h); CloseHandle(fd);
_TIFFfree(mbname); _TIFFfree(mbname);

View File

@@ -77,17 +77,6 @@ typedef struct client_info {
char *name; char *name;
} TIFFClientInfoLink; } 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. * Typedefs for ``method pointers'' used internally.
* these are depriciated and provided only for backwards compatibility * these are depriciated and provided only for backwards compatibility