summaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2021-12-13 22:30:58 +0100
committerHans Kristian Rosbach <hk-github@circlestorm.org>2021-12-24 12:52:14 +0100
commit8a378ba9b85e23a6e2e67b01a1b3d738e86faefe (patch)
treee9e0dc35c97219e5b7276f5c026f28ab6e9f02dd /deflate.c
parent2faaf5bbc993c09f7344353b824e1c1ad585627f (diff)
Fix deflateBound and compressBound returning very small size estimates.
Remove workaround in switchlevels.c, so we do actual testing of this. Use named defines instead of magic numbers where we can.
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/deflate.c b/deflate.c
index ca9dafa..031a1bb 100644
--- a/deflate.c
+++ b/deflate.c
@@ -685,11 +685,11 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
wraplen = 0;
break;
case 1: /* zlib wrapper */
- wraplen = 6 + (s->strstart ? 4 : 0);
+ wraplen = ZLIB_WRAPLEN + (s->strstart ? 4 : 0);
break;
#ifdef GZIP
case 2: /* gzip wrapper */
- wraplen = 18;
+ wraplen = GZIP_WRAPLEN;
if (s->gzhead != NULL) { /* user-supplied gzip header */
unsigned char *str;
if (s->gzhead->extra != NULL) {
@@ -713,7 +713,7 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
break;
#endif
default: /* for compiler happiness */
- wraplen = 6;
+ wraplen = ZLIB_WRAPLEN;
}
/* if not default parameters, return conservative bound */
@@ -721,8 +721,14 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
s->w_bits != 15 || HASH_BITS < 15)
return complen + wraplen;
- /* default settings: return tight bound for that case */
- return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13 - 6 + wraplen;
+#ifndef NO_QUICK_STRATEGY
+ return sourceLen /* The source size itself */
+ + DEFLATE_QUICK_OVERHEAD(sourceLen) /* Source encoding overhead, padded to next full byte */
+ + DEFLATE_BLOCK_OVERHEAD /* Deflate block overhead bytes */
+ + wraplen; /* none, zlib or gzip wrapper */
+#else
+ return sourceLen + (sourceLen >> 4) + 7 + wraplen;
+#endif
}
/* =========================================================================