From: Przemyslaw Skibinski Date: Wed, 18 Jan 2017 11:08:08 +0000 (+0100) Subject: gzlib.c updated to zlib 1.2.11 X-Git-Tag: v1.1.3^2~23^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f82aad187e6d5e505f0a0ffc25d9c90eec57461;p=thirdparty%2Fzstd.git gzlib.c updated to zlib 1.2.11 --- diff --git a/zlibWrapper/gzlib.c b/zlibWrapper/gzlib.c index 932319af6..2caf54e54 100644 --- a/zlibWrapper/gzlib.c +++ b/zlibWrapper/gzlib.c @@ -1,14 +1,14 @@ /* gzlib.c contains minimal changes required to be compiled with zlibWrapper: - * - gz_statep was converted to union to work with -Wstrict-aliasing=1 */ + * - gz_statep was converted to union to work with -Wstrict-aliasing=1 */ /* gzlib.c -- zlib functions common to reading and writing gzip files - * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see http://www.zlib.net/zlib_license.html + * Copyright (C) 2004-2017 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h */ #include "gzguts.h" -#if defined(_WIN32) && !defined(__BORLANDC__) +#if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__) # define LSEEK _lseeki64 #else #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 @@ -97,7 +97,7 @@ local gzFile gz_open(path, fd, mode) const char *mode; { gz_statep state; - size_t len; + z_size_t len; int oflag; #ifdef O_CLOEXEC int cloexec = 0; @@ -191,10 +191,10 @@ local gzFile gz_open(path, fd, mode) } /* save the path name for error messages */ -#ifdef _WIN32 +#ifdef WIDECHAR if (fd == -2) { len = wcstombs(NULL, path, 0); - if (len == (size_t)-1) + if (len == (z_size_t)-1) len = 0; } else @@ -205,7 +205,7 @@ local gzFile gz_open(path, fd, mode) free(state.state); return NULL; } -#ifdef _WIN32 +#ifdef WIDECHAR if (fd == -2) if (len) wcstombs(state.state->path, path, len + 1); @@ -214,7 +214,7 @@ local gzFile gz_open(path, fd, mode) else #endif #if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(state.state->path, len + 1, "%s", (const char *)path); + (void)snprintf(state.state->path, len + 1, "%s", (const char *)path); #else strcpy(state.state->path, path); #endif @@ -242,7 +242,7 @@ local gzFile gz_open(path, fd, mode) /* open the file with the appropriate flags (or just use fd) */ state.state->fd = fd > -1 ? fd : ( -#ifdef _WIN32 +#ifdef WIDECHAR fd == -2 ? _wopen(path, oflag, 0666) : #endif open((const char *)path, oflag, 0666)); @@ -251,8 +251,10 @@ local gzFile gz_open(path, fd, mode) free(state.state); return NULL; } - if (state.state->mode == GZ_APPEND) + if (state.state->mode == GZ_APPEND) { + LSEEK(state.state->fd, 0, SEEK_END); /* so gzoffset() is correct */ state.state->mode = GZ_WRITE; /* simplify later checks */ + } /* save the current position for rewinding (only if reading) */ if (state.state->mode == GZ_READ) { @@ -294,7 +296,7 @@ gzFile ZEXPORT gzdopen(fd, mode) if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL) return NULL; #if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(path, 7 + 3 * sizeof(int), "", fd); /* for debugging */ + (void)snprintf(path, 7 + 3 * sizeof(int), "", fd); #else sprintf(path, "", fd); /* for debugging */ #endif @@ -304,7 +306,7 @@ gzFile ZEXPORT gzdopen(fd, mode) } /* -- see zlib.h -- */ -#ifdef _WIN32 +#ifdef WIDECHAR gzFile ZEXPORT gzopen_w(path, mode) const wchar_t *path; const char *mode; @@ -332,6 +334,8 @@ int ZEXPORT gzbuffer(file, size) return -1; /* check and set requested size */ + if ((size << 1) < size) + return -1; /* need to be able to double it */ if (size < 2) size = 2; /* need two bytes to check magic header */ state.state->want = size; @@ -569,8 +573,8 @@ void ZEXPORT gzclearerr(file) gz_error(state, Z_OK, NULL); } -/* Create an error message in allocated memory and set state->err and - state->msg accordingly. Free any previous error message already there. Do +/* Create an error message in allocated memory and set state.state->err and + state.state->msg accordingly. Free any previous error message already there. Do not try to free or allocate space if the error is Z_MEM_ERROR (out of memory). Simply save the error message as a static string. If there is an allocation failure constructing the error message, then convert the error to @@ -587,7 +591,7 @@ void ZLIB_INTERNAL gz_error(state, err, msg) state.state->msg = NULL; } - /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ + /* if fatal, set state.state->x.have to 0 so that the gzgetc() macro fails */ if (err != Z_OK && err != Z_BUF_ERROR) state.state->x.have = 0; @@ -607,14 +611,13 @@ void ZLIB_INTERNAL gz_error(state, err, msg) return; } #if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(state.state->msg, strlen(state.state->path) + strlen(msg) + 3, - "%s%s%s", state.state->path, ": ", msg); + (void)snprintf(state.state->msg, strlen(state.state->path) + strlen(msg) + 3, + "%s%s%s", state.state->path, ": ", msg); #else strcpy(state.state->msg, state.state->path); strcat(state.state->msg, ": "); strcat(state.state->msg, msg); #endif - return; } #ifndef INT_MAX