aboutsummaryrefslogtreecommitdiff
path: root/compress.c
diff options
context:
space:
mode:
authorMark Adler <git@madler.net>2026-01-04 10:34:44 -0600
committerMark Adler <git@madler.net>2026-01-05 15:03:04 -0600
commit916dc1ac351795c9bf86a3d19c3667b014b9d28e (patch)
tree08efd9aa0c5387fe80c1ce15a9fdb0ca8e29c01c /compress.c
parentfd366384cf324d750596feb03be44ddf4d1e6acd (diff)
downloadzlib-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 'compress.c')
-rw-r--r--compress.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/compress.c b/compress.c
index f43bacf7..0c709d06 100644
--- a/compress.c
+++ b/compress.c
@@ -69,7 +69,12 @@ int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
69 If the default memLevel or windowBits for deflateInit() is changed, then 69 If the default memLevel or windowBits for deflateInit() is changed, then
70 this function needs to be updated. 70 this function needs to be updated.
71 */ 71 */
72z_size_t ZEXPORT compressBound_z(z_size_t sourceLen) {
73 z_size_t bound = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
74 (sourceLen >> 25) + 13;
75 return bound < sourceLen ? (z_size_t)-1 : bound;
76}
72uLong ZEXPORT compressBound(uLong sourceLen) { 77uLong ZEXPORT compressBound(uLong sourceLen) {
73 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 78 z_size_t bound = compressBound_z(sourceLen);
74 (sourceLen >> 25) + 13; 79 return (uLong)bound != bound ? (uLong)-1 : (uLong)bound;
75} 80}