diff options
author | Hans Kristian Rosbach <hk-git@circlestorm.org> | 2021-12-13 22:30:58 +0100 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2021-12-24 12:52:14 +0100 |
commit | 8a378ba9b85e23a6e2e67b01a1b3d738e86faefe (patch) | |
tree | e9e0dc35c97219e5b7276f5c026f28ab6e9f02dd /compress.c | |
parent | 2faaf5bbc993c09f7344353b824e1c1ad585627f (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 'compress.c')
-rw-r--r-- | compress.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -3,8 +3,8 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#define ZLIB_INTERNAL #include "zbuild.h" +#include "zutil.h" #if defined(ZLIB_COMPAT) # include "zlib.h" #else @@ -74,10 +74,11 @@ int Z_EXPORT PREFIX(compress)(unsigned char *dest, z_size_t *destLen, const unsi */ z_size_t Z_EXPORT PREFIX(compressBound)(z_size_t sourceLen) { #ifndef NO_QUICK_STRATEGY - /* Quick deflate strategy worse case is 9 bits per literal, rounded to nearest byte, - plus the size of block & gzip headers and footers */ - return sourceLen + ((sourceLen + 13 + 7) >> 3) + 18; + 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 */ + + ZLIB_WRAPLEN; /* zlib wrapper */ #else - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13; + return sourceLen + (sourceLen >> 4) + 7 + ZLIB_WRAPLEN; #endif } |