]> git.lizzy.rs Git - zlib.git/blobdiff - gzwrite.c
Avoid adding empty gzip member after gzflush with Z_FINISH.
[zlib.git] / gzwrite.c
index 52381332edd157fcfc553a786c11b0fd9bf2f0b8..85b576ba3053700bacf6bee047d08dd11f677ebf 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -97,6 +97,15 @@ local int gz_comp(state, flush)
         return 0;
     }
 
+    /* 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 */
     ret = Z_OK;
     do {
@@ -134,7 +143,7 @@ local int gz_comp(state, flush)
 
     /* if that completed a deflate stream, allow another to start */
     if (flush == Z_FINISH)
-        deflateReset(strm);
+        state->reset = 1;
 
     /* all done, no errors */
     return 0;