From f1ebdd6a9c495a5db9a22aa80dd7d54ae7db42e9 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Wed, 28 Dec 2011 23:57:14 -0800 Subject: [PATCH] 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. --- deflate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deflate.c b/deflate.c index f27febb..5d1d7bd 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); } -- GitLab