From: Mark Adler Date: Thu, 29 Dec 2011 07:57:14 +0000 (-0800) Subject: Permit stronger flushes after Z_BLOCK flushes. X-Git-Tag: v1.2.5.3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1ebdd6a9c495a5db9a22aa80dd7d54ae7db42e9;p=thirdparty%2Fzlib-ng.git Permit stronger flushes after Z_BLOCK flushes. 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. --- diff --git a/deflate.c b/deflate.c index f27febbbd..5d1d7bd17 100644 --- 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); }