aboutsummaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2017-01-12 21:51:20 -0800
committerMark Adler <madler@alumni.caltech.edu>2017-01-15 09:07:14 -0800
commit4c7c90768308587884fab6159d93a4695a5ab1f0 (patch)
treed94773ee823574c484d4e93e669fe40f84b1ed22 /deflate.c
parent74d2696d87188f52296ee9c88f295eb0d896acf9 (diff)
downloadzlib-4c7c90768308587884fab6159d93a4695a5ab1f0.tar.gz
zlib-4c7c90768308587884fab6159d93a4695a5ab1f0.tar.bz2
zlib-4c7c90768308587884fab6159d93a4695a5ab1f0.zip
Fix deflate stored bug when pulling last block from window.
And some cosmetic cleanups.
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/deflate.c b/deflate.c
index 68a2e47..0aa020e 100644
--- a/deflate.c
+++ b/deflate.c
@@ -1671,8 +1671,6 @@ local block_state deflate_stored(s, flush)
1671 len = left + s->strm->avail_in; /* limit len to the input */ 1671 len = left + s->strm->avail_in; /* limit len to the input */
1672 if (len > have) 1672 if (len > have)
1673 len = have; /* limit len to the output */ 1673 len = have; /* limit len to the output */
1674 if (left > len)
1675 left = len; /* limit window pull to len */
1676 1674
1677 /* If the stored block would be less than min_block in length, or if 1675 /* If the stored block would be less than min_block in length, or if
1678 * unable to copy all of the available input when flushing, then try 1676 * unable to copy all of the available input when flushing, then try
@@ -1681,13 +1679,13 @@ local block_state deflate_stored(s, flush)
1681 */ 1679 */
1682 if (len < min_block && ((len == 0 && flush != Z_FINISH) || 1680 if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
1683 flush == Z_NO_FLUSH || 1681 flush == Z_NO_FLUSH ||
1684 len - left != s->strm->avail_in)) 1682 len != left + s->strm->avail_in))
1685 break; 1683 break;
1686 1684
1687 /* Make a dummy stored block in pending to get the header bytes, 1685 /* Make a dummy stored block in pending to get the header bytes,
1688 * including any pending bits. This also updates the debugging counts. 1686 * including any pending bits. This also updates the debugging counts.
1689 */ 1687 */
1690 last = flush == Z_FINISH && len - left == s->strm->avail_in ? 1 : 0; 1688 last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
1691 _tr_stored_block(s, (char *)0, 0L, last); 1689 _tr_stored_block(s, (char *)0, 0L, last);
1692 1690
1693 /* Replace the lengths in the dummy stored block with len. */ 1691 /* Replace the lengths in the dummy stored block with len. */
@@ -1699,14 +1697,16 @@ local block_state deflate_stored(s, flush)
1699 /* Write the stored block header bytes. */ 1697 /* Write the stored block header bytes. */
1700 flush_pending(s->strm); 1698 flush_pending(s->strm);
1701 1699
1702 /* Update debugging counts for the data about to be copied. */
1703#ifdef ZLIB_DEBUG 1700#ifdef ZLIB_DEBUG
1701 /* Update debugging counts for the data about to be copied. */
1704 s->compressed_len += len << 3; 1702 s->compressed_len += len << 3;
1705 s->bits_sent += len << 3; 1703 s->bits_sent += len << 3;
1706#endif 1704#endif
1707 1705
1708 /* Copy uncompressed bytes from the window to next_out. */ 1706 /* Copy uncompressed bytes from the window to next_out. */
1709 if (left) { 1707 if (left) {
1708 if (left > len)
1709 left = len;
1710 zmemcpy(s->strm->next_out, s->window + s->block_start, left); 1710 zmemcpy(s->strm->next_out, s->window + s->block_start, left);
1711 s->strm->next_out += left; 1711 s->strm->next_out += left;
1712 s->strm->avail_out -= left; 1712 s->strm->avail_out -= left;