[Zlib-devel] zlib 1.2.3.4 Winter Solstice Edition
Vincent Torri
vtorri at univ-evry.fr
Mon Dec 28 12:29:20 EST 2009
Hey,
about the Windows CE port: on Windows CE, file descriptors are HANDLE in
disguise and a negative value can be a valid 'file descriptor'. So
checking for fd that are negative is not correct. Checking with -1 is
better, i think.
See gzio.c, lines 195 and 253. If you think there's no problem elsewhere
(afaik, open() returns -1 on error, and fileno never fails (or has an
undefined behavior if the stream is not valid)). In addition it is what is
described in the comment of gz_open(), line 104.
Here is the patch:
--- gzio.c 2009-12-22 07:43:16.000000000 +0100
+++ gzio.c.new 2009-12-28 18:20:15.000000000 +0100
@@ -192,7 +192,7 @@
s->stream.avail_out = Z_BUFSIZE;
errno = 0;
- s->file = fd < 0 ? (use64 ? F_OPEN64(path, fmode) : F_OPEN(path, fmode)) :
+ s->file = fd == -1 ? (use64 ? F_OPEN64(path, fmode) : F_OPEN(path, fmode)) :
(FILE*)fdopen(fd, fmode);
if (s->file == NULL) {
@@ -250,7 +250,7 @@
{
char name[46]; /* allow for up to 128-bit integers */
- if (fd < 0) return (gzFile)Z_NULL;
+ if (fd == -1) return (gzFile)Z_NULL;
sprintf(name, "<fd:%d>", fd); /* for debugging */
return gz_open (name, mode, fd, 0);
More information about the Zlib-devel
mailing list