]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Permit stronger flushes after Z_BLOCK flushes.
authorMark Adler <madler@alumni.caltech.edu>
Thu, 29 Dec 2011 07:57:14 +0000 (23:57 -0800)
committerMark Adler <madler@alumni.caltech.edu>
Thu, 29 Dec 2011 07:57:14 +0000 (23:57 -0800)
The incorporation of the Z_BLOCK flush did not update the rejection
of lower ranked flushes immediately after higher ranked flushes with
no more input data.  This prevented an empty Z_SYNC_FLUSH right after
a Z_BLOCK flush, which would be desired to bring the deflate stream
to a byte boundary conditionally on whether or not it was already at
a byte boundary.  This patch re-ranks Z_BLOCK above Z_NO_FLUSH but
below Z_PARTIAL_FLUSH, allowing stronger empty flushes to follow a
Z_BLOCK flush.

deflate.c

index f27febbbd115dd76643c73ba49a0301c03c00610..5d1d7bd17ef0df5c74f75928e31e3dbf3f4f6596 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -155,6 +155,9 @@ local const config configuration_table[10] = {
 struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
 #endif
 
+/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
+#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
+
 /* ===========================================================================
  * Update a hash value with the given input byte
  * IN  assertion: all calls to to UPDATE_HASH are made with consecutive
@@ -858,7 +861,7 @@ int ZEXPORT deflate (strm, flush)
      * flushes. For repeated and useless calls with Z_FINISH, we keep
      * returning Z_STREAM_END instead of Z_BUF_ERROR.
      */
-    } else if (strm->avail_in == 0 && flush <= old_flush &&
+    } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
                flush != Z_FINISH) {
         ERR_RETURN(strm, Z_BUF_ERROR);
     }