diff options
Diffstat (limited to 'src/Common/zlib/gzwrite.c')
-rw-r--r-- | src/Common/zlib/gzwrite.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/Common/zlib/gzwrite.c b/src/Common/zlib/gzwrite.c index c7b5651d..a8ffc8f5 100644 --- a/src/Common/zlib/gzwrite.c +++ b/src/Common/zlib/gzwrite.c @@ -1,3 +1,3 @@ /* gzwrite.c -- zlib functions for writing gzip files - * Copyright (C) 2004-2017 Mark Adler + * Copyright (C) 2004-2019 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h @@ -99,2 +99,11 @@ local int gz_comp(state, flush) + /* check for a pending reset */ + if (state->reset) { + /* don't start a new gzip member unless there is data to write */ + if (strm->avail_in == 0) + return 0; + deflateReset(strm); + state->reset = 0; + } + /* run deflate() on provided input until it produces no more output */ @@ -136,3 +145,3 @@ local int gz_comp(state, flush) if (flush == Z_FINISH) - deflateReset(strm); + state->reset = 1; @@ -211,3 +220,3 @@ local z_size_t gz_write(state, buf, len) if (copy > len) - copy = len; + copy = (unsigned)len; memcpy(state->in + have, buf, copy); @@ -231,3 +240,3 @@ local z_size_t gz_write(state, buf, len) if (n > len) - n = len; + n = (unsigned)len; state->strm.avail_in = n; @@ -351,8 +360,7 @@ int ZEXPORT gzputc(file, c) /* -- see zlib.h -- */ -int ZEXPORT gzputs(file, str) +int ZEXPORT gzputs(file, s) gzFile file; - const char *str; + const char *s; { - int ret; - z_size_t len; + z_size_t len, put; gz_statep state; @@ -369,5 +377,9 @@ int ZEXPORT gzputs(file, str) /* write string */ - len = strlen(str); - ret = gz_write(state, str, len); - return ret == 0 && len != 0 ? -1 : ret; + len = strlen(s); + if ((int)len < 0 || (unsigned)len != len) { + gz_error(state, Z_STREAM_ERROR, "string length does not fit in int"); + return -1; + } + put = gz_write(state, s, len); + return put < len ? -1 : (int)len; } @@ -443,3 +455,3 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) return state->err; - memcpy(state->in, state->in + state->size, left); + memmove(state->in, state->in + state->size, left); strm->next_in = state->in; @@ -542,3 +554,3 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, return state->err; - memcpy(state->in, state->in + state->size, left); + memmove(state->in, state->in + state->size, left); strm->next_in = state->in; |