Skip to content

Commit

Permalink
Use named define instead of magic number for deflate block header ove…
Browse files Browse the repository at this point in the history
…rhead.
  • Loading branch information
Dead2 committed Dec 14, 2021
1 parent 4134223 commit 911e640
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ z_size_t Z_EXPORT PREFIX(compressBound)(z_size_t sourceLen) {
/* Quick deflate strategy worse case is 9 bits per literal, rounded to nearest byte,
plus the size of block & zlib headers and footers, and one extra byte for padding
extremely small blocks */
return sourceLen + ((sourceLen + 13 + 7) >> 3) + ZLIB_WRAPLEN + 1;
return sourceLen + ((sourceLen + DEFLATE_WRAPBITS + 7) >> 3) + ZLIB_WRAPLEN + 1;
#else
return sourceLen + (sourceLen >> 4) + 7 + ZLIB_WRAPLEN;
#endif
Expand Down
2 changes: 1 addition & 1 deletion deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
/* Quick deflate strategy worst case is 9 bits per literal, rounded to nearest byte,
plus the size of block headers & wrappers, and one extra byte for padding
extremely small blocks */
return sourceLen + ((sourceLen + 13 + 7) >> 3) + wraplen + 1;
return sourceLen + ((sourceLen + DEFLATE_WRAPBITS + 7) >> 3) + wraplen + 1;
#else
return sourceLen + (sourceLen >> 4) + 7 + wraplen;
#endif
Expand Down
5 changes: 3 additions & 2 deletions zutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
#define ADLER32_INITIAL_VALUE 1 /* initial adler-32 hash value */
#define CRC32_INITIAL_VALUE 0 /* initial crc-32 hash value */

#define ZLIB_WRAPLEN 6 /* zlib format overhead */
#define GZIP_WRAPLEN 18 /* gzip format overhead */
#define ZLIB_WRAPLEN 6 /* zlib format overhead */
#define GZIP_WRAPLEN 18 /* gzip format overhead */
#define DEFLATE_WRAPBITS 13 /* deflate block overhead: 3 bits for block start + 10 bits for block end */

/* target dependencies */

Expand Down

0 comments on commit 911e640

Please sign in to comment.