diff options
| author | Mark Adler <git@madler.net> | 2026-01-04 10:34:44 -0600 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2026-01-05 15:03:04 -0600 |
| commit | 916dc1ac351795c9bf86a3d19c3667b014b9d28e (patch) | |
| tree | 08efd9aa0c5387fe80c1ce15a9fdb0ca8e29c01c /zlib.h | |
| parent | fd366384cf324d750596feb03be44ddf4d1e6acd (diff) | |
| download | zlib-916dc1ac351795c9bf86a3d19c3667b014b9d28e.tar.gz zlib-916dc1ac351795c9bf86a3d19c3667b014b9d28e.tar.bz2 zlib-916dc1ac351795c9bf86a3d19c3667b014b9d28e.zip | |
Add compressBound_z and deflateBound_z functions for large values.
These take and return size_t integers, instead of unsigned longs,
for those platforms with 32-bit longs. This commit also assures
that overflows of either integer type results in the maximum value
for that type, instead of wrapping to small values.
Diffstat (limited to 'zlib.h')
| -rw-r--r-- | zlib.h | 11 |
1 files changed, 9 insertions, 2 deletions
| @@ -765,8 +765,8 @@ ZEXTERN int ZEXPORT deflateTune(z_streamp strm, | |||
| 765 | returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. | 765 | returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. |
| 766 | */ | 766 | */ |
| 767 | 767 | ||
| 768 | ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, | 768 | ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen); |
| 769 | uLong sourceLen); | 769 | ZEXTERN z_size_t ZEXPORT deflateBound_z(z_streamp strm, z_size_t sourceLen); |
| 770 | /* | 770 | /* |
| 771 | deflateBound() returns an upper bound on the compressed size after | 771 | deflateBound() returns an upper bound on the compressed size after |
| 772 | deflation of sourceLen bytes. It must be called after deflateInit() or | 772 | deflation of sourceLen bytes. It must be called after deflateInit() or |
| @@ -778,6 +778,9 @@ ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, | |||
| 778 | to return Z_STREAM_END. Note that it is possible for the compressed size to | 778 | to return Z_STREAM_END. Note that it is possible for the compressed size to |
| 779 | be larger than the value returned by deflateBound() if flush options other | 779 | be larger than the value returned by deflateBound() if flush options other |
| 780 | than Z_FINISH or Z_NO_FLUSH are used. | 780 | than Z_FINISH or Z_NO_FLUSH are used. |
| 781 | |||
| 782 | delfateBound_z() is the same, but takes and returns a size_t length for | ||
| 783 | those systems on which a long is 32 bits. | ||
| 781 | */ | 784 | */ |
| 782 | 785 | ||
| 783 | ZEXTERN int ZEXPORT deflatePending(z_streamp strm, | 786 | ZEXTERN int ZEXPORT deflatePending(z_streamp strm, |
| @@ -1293,10 +1296,14 @@ ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, | |||
| 1293 | */ | 1296 | */ |
| 1294 | 1297 | ||
| 1295 | ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); | 1298 | ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); |
| 1299 | ZEXTERN z_size_t ZEXPORT compressBound_z(z_size_t sourceLen); | ||
| 1296 | /* | 1300 | /* |
| 1297 | compressBound() returns an upper bound on the compressed size after | 1301 | compressBound() returns an upper bound on the compressed size after |
| 1298 | compress() or compress2() on sourceLen bytes. It would be used before a | 1302 | compress() or compress2() on sourceLen bytes. It would be used before a |
| 1299 | compress() or compress2() call to allocate the destination buffer. | 1303 | compress() or compress2() call to allocate the destination buffer. |
| 1304 | |||
| 1305 | compressBound_z() is the same, but takes and returns a size_t length for | ||
| 1306 | those systems on which a long is 32 bits. | ||
| 1300 | */ | 1307 | */ |
| 1301 | 1308 | ||
| 1302 | ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, | 1309 | ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, |
