]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fixed missing compressed_len count in deflate_quick when ZLIB_DEBUG defined. Put...
authorNathan Moinvaziri <nathan@nathanm.com>
Fri, 7 Feb 2020 23:01:10 +0000 (15:01 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 8 Feb 2020 12:53:43 +0000 (13:53 +0100)
arch/x86/deflate_quick.c
deflate.h

index f79d20fce64cf516ae1ec3d00d90483b7e19eef5..9f6d6b6d9692823282dbc499d299d730c915c460 100644 (file)
@@ -135,6 +135,9 @@ static inline void static_emit_ptr(deflate_state *const s, const int lc, const u
 
     send_bits(s, code1, len1, bi_buf, bi_valid);
     send_bits(s, code2, len2, bi_buf, bi_valid);
+#ifdef ZLIB_DEBUG
+    s->compressed_len += len1 + len2;
+#endif
 
     s->bi_valid = bi_valid;
     s->bi_buf = bi_buf;
@@ -147,6 +150,9 @@ static inline void static_emit_lit(deflate_state *const s, const int lit) {
     uint32_t bi_buf = s->bi_buf;
 
     send_bits(s, static_ltree[lit].Code, static_ltree[lit].Len, bi_buf, bi_valid);
+#ifdef ZLIB_DEBUG
+    s->compressed_len += static_ltree[lit].Len;
+#endif
 
     s->bi_valid = bi_valid;
     s->bi_buf = bi_buf;
index 8032fccba143099dcea48b8391c27a965d502973..275261e0a004ccb323a73cd2cc3da7393324bb83 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -473,7 +473,7 @@ extern const unsigned char ZLIB_INTERNAL zng_dist_code[];
 #ifdef ZLIB_DEBUG
 #  define send_debug_trace(s, value, length) {\
         Tracevv((stderr, " l %2d v %4x ", length, value));\
-        Assert(length > 0 && length <= BIT_BUF_SIZE - 1, "invalid length");\
+        Assert(length > 0 && length <= BIT_BUF_SIZE, "invalid length");\
         s->bits_sent += (unsigned long)length;\
     }
 #else
@@ -488,19 +488,18 @@ extern const unsigned char ZLIB_INTERNAL zng_dist_code[];
     uint32_t val = (uint32_t)t_val;\
     uint32_t len = (uint32_t)t_len;\
     send_debug_trace(s, val, len);\
-    if (bits_valid == BIT_BUF_SIZE) {\
+    if (bits_valid + len < BIT_BUF_SIZE) {\
+        bit_buf |= val << bits_valid;\
+        bits_valid += len;\
+    } else if (bits_valid == BIT_BUF_SIZE) {\
         put_uint32(s, bit_buf);\
         bit_buf = val;\
         bits_valid = len;\
-    } else if (bits_valid + len >= BIT_BUF_SIZE) {\
+    } else {\
         bit_buf |= val << bits_valid;\
         put_uint32(s, bit_buf);\
         bit_buf = val >> (BIT_BUF_SIZE - bits_valid);\
         bits_valid += len - BIT_BUF_SIZE;\
-    } else {\
-        bit_buf |= val << bits_valid;\
-        bits_valid += len;\
     }\
 }
-
 #endif /* DEFLATE_H_ */