369dca
From f1b8edadc3c733990f8a8de4d643f968e571ae85 Mon Sep 17 00:00:00 2001
369dca
From: Adam Tkac <atkac@redhat.com>
369dca
Date: Fri, 17 Aug 2012 15:13:48 +0200
369dca
Subject: [PATCH] Rank Z_BLOCK flush below Z_PARTIAL_FLUSH only when last
369dca
 flush was Z_BLOCK.
369dca
369dca
This fixes regression introduced by f1ebdd6a9c495a5db9a22aa80dd7d54ae7db42e9
369dca
(Permit stronger flushes after Z_BLOCK flushes.). Now this code is valid
369dca
again:
369dca
369dca
deflate(stream, Z_SYNC_FLUSH);
369dca
deflateParams(stream, newLevel, Z_DEFAULT_STRATEGY);
369dca
369dca
Signed-off-by: Adam Tkac <atkac@redhat.com>
369dca
---
369dca
 deflate.c | 13 ++++++++++---
369dca
 1 file changed, 10 insertions(+), 3 deletions(-)
369dca
369dca
diff --git a/deflate.c b/deflate.c
369dca
index 9e4c2cb..3422f72 100644
369dca
--- a/deflate.c
369dca
+++ b/deflate.c
369dca
@@ -882,9 +882,16 @@ int ZEXPORT deflate (strm, flush)
369dca
      * flushes. For repeated and useless calls with Z_FINISH, we keep
369dca
      * returning Z_STREAM_END instead of Z_BUF_ERROR.
369dca
      */
369dca
-    } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
369dca
-               flush != Z_FINISH) {
369dca
-        ERR_RETURN(strm, Z_BUF_ERROR);
369dca
+    } else if (strm->avail_in == 0 && flush != Z_FINISH) {
369dca
+        char err;
369dca
+
369dca
+        /* Degrade Z_BLOCK only when last flush was Z_BLOCK */
369dca
+        err = (old_flush == Z_BLOCK) ?
369dca
+              RANK(flush) <= RANK(old_flush) : flush <= old_flush;
369dca
+
369dca
+        if (err) {
369dca
+            ERR_RETURN(strm, Z_BUF_ERROR);
369dca
+        }
369dca
     }
369dca
 
369dca
     /* User must not provide more input after the first FINISH: */
369dca
-- 
369dca
1.7.11.4
369dca