提交 4c7c9076 编写于 作者: M Mark Adler

Fix deflate stored bug when pulling last block from window.

And some cosmetic cleanups.
上级 74d2696d
...@@ -1671,8 +1671,6 @@ local block_state deflate_stored(s, flush) ...@@ -1671,8 +1671,6 @@ local block_state deflate_stored(s, flush)
len = left + s->strm->avail_in; /* limit len to the input */ len = left + s->strm->avail_in; /* limit len to the input */
if (len > have) if (len > have)
len = have; /* limit len to the output */ len = have; /* limit len to the output */
if (left > len)
left = len; /* limit window pull to len */
/* If the stored block would be less than min_block in length, or if /* If the stored block would be less than min_block in length, or if
* unable to copy all of the available input when flushing, then try * unable to copy all of the available input when flushing, then try
...@@ -1681,13 +1679,13 @@ local block_state deflate_stored(s, flush) ...@@ -1681,13 +1679,13 @@ local block_state deflate_stored(s, flush)
*/ */
if (len < min_block && ((len == 0 && flush != Z_FINISH) || if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
flush == Z_NO_FLUSH || flush == Z_NO_FLUSH ||
len - left != s->strm->avail_in)) len != left + s->strm->avail_in))
break; break;
/* Make a dummy stored block in pending to get the header bytes, /* Make a dummy stored block in pending to get the header bytes,
* including any pending bits. This also updates the debugging counts. * including any pending bits. This also updates the debugging counts.
*/ */
last = flush == Z_FINISH && len - left == s->strm->avail_in ? 1 : 0; last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
_tr_stored_block(s, (char *)0, 0L, last); _tr_stored_block(s, (char *)0, 0L, last);
/* Replace the lengths in the dummy stored block with len. */ /* Replace the lengths in the dummy stored block with len. */
...@@ -1699,14 +1697,16 @@ local block_state deflate_stored(s, flush) ...@@ -1699,14 +1697,16 @@ local block_state deflate_stored(s, flush)
/* Write the stored block header bytes. */ /* Write the stored block header bytes. */
flush_pending(s->strm); flush_pending(s->strm);
/* Update debugging counts for the data about to be copied. */
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
/* Update debugging counts for the data about to be copied. */
s->compressed_len += len << 3; s->compressed_len += len << 3;
s->bits_sent += len << 3; s->bits_sent += len << 3;
#endif #endif
/* Copy uncompressed bytes from the window to next_out. */ /* Copy uncompressed bytes from the window to next_out. */
if (left) { if (left) {
if (left > len)
left = len;
zmemcpy(s->strm->next_out, s->window + s->block_start, left); zmemcpy(s->strm->next_out, s->window + s->block_start, left);
s->strm->next_out += left; s->strm->next_out += left;
s->strm->avail_out -= left; s->strm->avail_out -= left;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册