diff options
| author | Mark Adler <git@madler.net> | 2026-02-09 07:06:18 -0800 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2026-02-09 16:34:03 -0800 |
| commit | 81c41dd5c5ddfff868d8d394fc21fdfa4e55de92 (patch) | |
| tree | d1682dacb5b31c0d4d48d05881d1b35f9a48fa26 | |
| parent | fd2fe58bf43f451b04402f38d8787e4100ef48bf (diff) | |
| download | zlib-81c41dd5c5ddfff868d8d394fc21fdfa4e55de92.tar.gz zlib-81c41dd5c5ddfff868d8d394fc21fdfa4e55de92.tar.bz2 zlib-81c41dd5c5ddfff868d8d394fc21fdfa4e55de92.zip | |
Also clean up conversion warnings.
| -rw-r--r-- | deflate.c | 46 | ||||
| -rw-r--r-- | zlib.h | 5 |
2 files changed, 33 insertions, 18 deletions
| @@ -261,7 +261,14 @@ local void fill_window(deflate_state *s) { | |||
| 261 | more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); | 261 | more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); |
| 262 | 262 | ||
| 263 | /* Deal with !@#$% 64K limit: */ | 263 | /* Deal with !@#$% 64K limit: */ |
| 264 | #ifdef _MSC_VER | ||
| 265 | #pragma warning(push) | ||
| 266 | #pragma warning(disable: 4127) | ||
| 267 | #endif | ||
| 264 | if (sizeof(int) <= 2) { | 268 | if (sizeof(int) <= 2) { |
| 269 | #ifdef _MSC_VER | ||
| 270 | #pragma warning(pop) | ||
| 271 | #endif | ||
| 265 | if (more == 0 && s->strstart == 0 && s->lookahead == 0) { | 272 | if (more == 0 && s->strstart == 0 && s->lookahead == 0) { |
| 266 | more = wsize; | 273 | more = wsize; |
| 267 | 274 | ||
| @@ -715,10 +722,15 @@ int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { | |||
| 715 | /* ========================================================================= */ | 722 | /* ========================================================================= */ |
| 716 | int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { | 723 | int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { |
| 717 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | 724 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; |
| 718 | if (pending != Z_NULL) | ||
| 719 | *pending = strm->state->pending; | ||
| 720 | if (bits != Z_NULL) | 725 | if (bits != Z_NULL) |
| 721 | *bits = strm->state->bi_valid; | 726 | *bits = strm->state->bi_valid; |
| 727 | if (pending != Z_NULL) { | ||
| 728 | *pending = (unsigned)strm->state->pending; | ||
| 729 | if (*pending != strm->state->pending) { | ||
| 730 | *pending = (unsigned)-1; | ||
| 731 | return Z_BUF_ERROR; | ||
| 732 | } | ||
| 733 | } | ||
| 722 | return Z_OK; | 734 | return Z_OK; |
| 723 | } | 735 | } |
| 724 | 736 | ||
| @@ -941,8 +953,8 @@ local void flush_pending(z_streamp strm) { | |||
| 941 | deflate_state *s = strm->state; | 953 | deflate_state *s = strm->state; |
| 942 | 954 | ||
| 943 | _tr_flush_bits(s); | 955 | _tr_flush_bits(s); |
| 944 | len = s->pending; | 956 | len = s->pending > strm->avail_out ? strm->avail_out : |
| 945 | if (len > strm->avail_out) len = strm->avail_out; | 957 | (unsigned)s->pending; |
| 946 | if (len == 0) return; | 958 | if (len == 0) return; |
| 947 | 959 | ||
| 948 | zmemcpy(strm->next_out, s->pending_out, len); | 960 | zmemcpy(strm->next_out, s->pending_out, len); |
| @@ -962,8 +974,8 @@ local void flush_pending(z_streamp strm) { | |||
| 962 | #define HCRC_UPDATE(beg) \ | 974 | #define HCRC_UPDATE(beg) \ |
| 963 | do { \ | 975 | do { \ |
| 964 | if (s->gzhead->hcrc && s->pending > (beg)) \ | 976 | if (s->gzhead->hcrc && s->pending > (beg)) \ |
| 965 | strm->adler = crc32(strm->adler, s->pending_buf + (beg), \ | 977 | strm->adler = crc32_z(strm->adler, s->pending_buf + (beg), \ |
| 966 | s->pending - (beg)); \ | 978 | s->pending - (beg)); \ |
| 967 | } while (0) | 979 | } while (0) |
| 968 | 980 | ||
| 969 | /* ========================================================================= */ | 981 | /* ========================================================================= */ |
| @@ -1097,8 +1109,8 @@ int ZEXPORT deflate(z_streamp strm, int flush) { | |||
| 1097 | put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); | 1109 | put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); |
| 1098 | } | 1110 | } |
| 1099 | if (s->gzhead->hcrc) | 1111 | if (s->gzhead->hcrc) |
| 1100 | strm->adler = crc32(strm->adler, s->pending_buf, | 1112 | strm->adler = crc32_z(strm->adler, s->pending_buf, |
| 1101 | s->pending); | 1113 | s->pending); |
| 1102 | s->gzindex = 0; | 1114 | s->gzindex = 0; |
| 1103 | s->status = EXTRA_STATE; | 1115 | s->status = EXTRA_STATE; |
| 1104 | } | 1116 | } |
| @@ -1106,9 +1118,9 @@ int ZEXPORT deflate(z_streamp strm, int flush) { | |||
| 1106 | if (s->status == EXTRA_STATE) { | 1118 | if (s->status == EXTRA_STATE) { |
| 1107 | if (s->gzhead->extra != Z_NULL) { | 1119 | if (s->gzhead->extra != Z_NULL) { |
| 1108 | ulg beg = s->pending; /* start of bytes to update crc */ | 1120 | ulg beg = s->pending; /* start of bytes to update crc */ |
| 1109 | uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex; | 1121 | ulg left = (s->gzhead->extra_len & 0xffff) - s->gzindex; |
| 1110 | while (s->pending + left > s->pending_buf_size) { | 1122 | while (s->pending + left > s->pending_buf_size) { |
| 1111 | uInt copy = s->pending_buf_size - s->pending; | 1123 | ulg copy = s->pending_buf_size - s->pending; |
| 1112 | zmemcpy(s->pending_buf + s->pending, | 1124 | zmemcpy(s->pending_buf + s->pending, |
| 1113 | s->gzhead->extra + s->gzindex, copy); | 1125 | s->gzhead->extra + s->gzindex, copy); |
| 1114 | s->pending = s->pending_buf_size; | 1126 | s->pending = s->pending_buf_size; |
| @@ -1659,7 +1671,7 @@ local block_state deflate_stored(deflate_state *s, int flush) { | |||
| 1659 | * this is 32K. This can be as small as 507 bytes for memLevel == 1. For | 1671 | * this is 32K. This can be as small as 507 bytes for memLevel == 1. For |
| 1660 | * large input and output buffers, the stored block size will be larger. | 1672 | * large input and output buffers, the stored block size will be larger. |
| 1661 | */ | 1673 | */ |
| 1662 | unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size); | 1674 | unsigned min_block = (unsigned)(MIN(s->pending_buf_size - 5, s->w_size)); |
| 1663 | 1675 | ||
| 1664 | /* Copy as many min_block or larger stored blocks directly to next_out as | 1676 | /* Copy as many min_block or larger stored blocks directly to next_out as |
| 1665 | * possible. If flushing, copy the remaining available input to next_out as | 1677 | * possible. If flushing, copy the remaining available input to next_out as |
| @@ -1674,12 +1686,12 @@ local block_state deflate_stored(deflate_state *s, int flush) { | |||
| 1674 | * would be copied from what's left in the window. | 1686 | * would be copied from what's left in the window. |
| 1675 | */ | 1687 | */ |
| 1676 | len = MAX_STORED; /* maximum deflate stored block length */ | 1688 | len = MAX_STORED; /* maximum deflate stored block length */ |
| 1677 | have = (s->bi_valid + 42) >> 3; /* number of header bytes */ | 1689 | have = ((unsigned)s->bi_valid + 42) >> 3; /* bytes in header */ |
| 1678 | if (s->strm->avail_out < have) /* need room for header */ | 1690 | if (s->strm->avail_out < have) /* need room for header */ |
| 1679 | break; | 1691 | break; |
| 1680 | /* maximum stored block length that will fit in avail_out: */ | 1692 | /* maximum stored block length that will fit in avail_out: */ |
| 1681 | have = s->strm->avail_out - have; | 1693 | have = s->strm->avail_out - have; |
| 1682 | left = s->strstart - s->block_start; /* bytes left in window */ | 1694 | left = (unsigned)(s->strstart - s->block_start); /* window bytes */ |
| 1683 | if (len > (ulg)left + s->strm->avail_in) | 1695 | if (len > (ulg)left + s->strm->avail_in) |
| 1684 | len = left + s->strm->avail_in; /* limit len to the input */ | 1696 | len = left + s->strm->avail_in; /* limit len to the input */ |
| 1685 | if (len > have) | 1697 | if (len > have) |
| @@ -1787,7 +1799,7 @@ local block_state deflate_stored(deflate_state *s, int flush) { | |||
| 1787 | return block_done; | 1799 | return block_done; |
| 1788 | 1800 | ||
| 1789 | /* Fill the window with any remaining input. */ | 1801 | /* Fill the window with any remaining input. */ |
| 1790 | have = s->window_size - s->strstart; | 1802 | have = (unsigned)(s->window_size - s->strstart); |
| 1791 | if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) { | 1803 | if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) { |
| 1792 | /* Slide the window down. */ | 1804 | /* Slide the window down. */ |
| 1793 | s->block_start -= s->w_size; | 1805 | s->block_start -= s->w_size; |
| @@ -1814,11 +1826,11 @@ local block_state deflate_stored(deflate_state *s, int flush) { | |||
| 1814 | * have enough input for a worthy block, or if flushing and there is enough | 1826 | * have enough input for a worthy block, or if flushing and there is enough |
| 1815 | * room for the remaining input as a stored block in the pending buffer. | 1827 | * room for the remaining input as a stored block in the pending buffer. |
| 1816 | */ | 1828 | */ |
| 1817 | have = (s->bi_valid + 42) >> 3; /* number of header bytes */ | 1829 | have = ((unsigned)s->bi_valid + 42) >> 3; /* bytes in header */ |
| 1818 | /* maximum stored block length that will fit in pending: */ | 1830 | /* maximum stored block length that will fit in pending: */ |
| 1819 | have = MIN(s->pending_buf_size - have, MAX_STORED); | 1831 | have = (unsigned)MIN(s->pending_buf_size - have, MAX_STORED); |
| 1820 | min_block = MIN(have, s->w_size); | 1832 | min_block = MIN(have, s->w_size); |
| 1821 | left = s->strstart - s->block_start; | 1833 | left = (unsigned)(s->strstart - s->block_start); |
| 1822 | if (left >= min_block || | 1834 | if (left >= min_block || |
| 1823 | ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH && | 1835 | ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH && |
| 1824 | s->strm->avail_in == 0 && left <= have)) { | 1836 | s->strm->avail_in == 0 && left <= have)) { |
| @@ -795,7 +795,10 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm, | |||
| 795 | or bits are Z_NULL, then those values are not set. | 795 | or bits are Z_NULL, then those values are not set. |
| 796 | 796 | ||
| 797 | deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source | 797 | deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source |
| 798 | stream state was inconsistent. | 798 | stream state was inconsistent. If an int is 16 bits and memLevel is 9, then |
| 799 | it is possible for the number of pending bytes to not fit in an unsigned. In | ||
| 800 | that case Z_BUF_ERROR is returned and *pending is set to the maximum value | ||
| 801 | of an unsigned. | ||
| 799 | */ | 802 | */ |
| 800 | 803 | ||
| 801 | ZEXTERN int ZEXPORT deflateUsed(z_streamp strm, | 804 | ZEXTERN int ZEXPORT deflateUsed(z_streamp strm, |
