diff --git a/deflate.c b/deflate.c index 3c302bc..1ab1635 100644 --- a/deflate.c +++ b/deflate.c @@ -1110,7 +1110,6 @@ int ZEXPORT deflate (strm, flush) } if (flush != Z_FINISH) return Z_OK; - if (s->wrap <= 0) return Z_STREAM_END; /* Write the trailer */ #ifdef GZIP @@ -1126,7 +1125,7 @@ int ZEXPORT deflate (strm, flush) } else #endif - { + if (s->wrap == 1) { putShortMSB(s, (uInt)(strm->adler >> 16)); putShortMSB(s, (uInt)(strm->adler & 0xffff)); } @@ -1135,7 +1134,11 @@ int ZEXPORT deflate (strm, flush) * to flush the rest. */ if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; + if (s->pending == 0) { + Assert(s->bi_valid == 0, "bi_buf not flushed"); + return Z_STREAM_END; + } + return Z_OK; } /* ========================================================================= */