diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-12-29 13:19:27 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2012-01-07 14:08:02 -0800 |
commit | 0b828b4aa6c962ab46eae624578d77b35395b2c1 (patch) | |
tree | 6c61daa3f02cd938d5f2434a3c3be2998866a43d /deflate.c | |
parent | 8f5eceefe8b384d7c18813519cb337efef21a0f3 (diff) | |
download | zlib-0b828b4aa6c962ab46eae624578d77b35395b2c1.tar.gz zlib-0b828b4aa6c962ab46eae624578d77b35395b2c1.tar.bz2 zlib-0b828b4aa6c962ab46eae624578d77b35395b2c1.zip |
Write out all of the available bits when using Z_BLOCK.
Previously, the bit buffer would hold 1 to 16 bits after "all" of the
output is provided after a Z_BLOCK deflate() call. Now at most seven
bits remain in the output buffer after Z_BLOCK. flush_pending() now
flushes the bit buffer before copying out the byte buffer, in order
for it to really flush as much as possible.
Diffstat (limited to 'deflate.c')
-rw-r--r-- | deflate.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -638,19 +638,22 @@ local void putShortMSB (s, b) | |||
638 | local void flush_pending(strm) | 638 | local void flush_pending(strm) |
639 | z_streamp strm; | 639 | z_streamp strm; |
640 | { | 640 | { |
641 | unsigned len = strm->state->pending; | 641 | unsigned len; |
642 | deflate_state *s = strm->state; | ||
642 | 643 | ||
644 | _tr_flush_bits(s); | ||
645 | len = s->pending; | ||
643 | if (len > strm->avail_out) len = strm->avail_out; | 646 | if (len > strm->avail_out) len = strm->avail_out; |
644 | if (len == 0) return; | 647 | if (len == 0) return; |
645 | 648 | ||
646 | zmemcpy(strm->next_out, strm->state->pending_out, len); | 649 | zmemcpy(strm->next_out, s->pending_out, len); |
647 | strm->next_out += len; | 650 | strm->next_out += len; |
648 | strm->state->pending_out += len; | 651 | s->pending_out += len; |
649 | strm->total_out += len; | 652 | strm->total_out += len; |
650 | strm->avail_out -= len; | 653 | strm->avail_out -= len; |
651 | strm->state->pending -= len; | 654 | s->pending -= len; |
652 | if (strm->state->pending == 0) { | 655 | if (s->pending == 0) { |
653 | strm->state->pending_out = strm->state->pending_buf; | 656 | s->pending_out = s->pending_buf; |
654 | } | 657 | } |
655 | } | 658 | } |
656 | 659 | ||