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"
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)
{

View File

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

View File

@ -77,17 +77,6 @@ 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