]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Remove branch that is almost impossible to hit in bi_flush().
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Wed, 7 Feb 2024 18:21:36 +0000 (19:21 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Mon, 12 Feb 2024 13:37:19 +0000 (14:37 +0100)
Add case that handles sizes >=48.

trees.c

diff --git a/trees.c b/trees.c
index 44b4a8786fd8964a85a3692831045a432fde9905..4189cc738eb7071e3b064bf4b2e5f7b8d298d3a3 100644 (file)
--- a/trees.c
+++ b/trees.c
@@ -791,26 +791,25 @@ static int detect_data_type(deflate_state *s) {
  * Flush the bit buffer, keeping at most 7 bits in it.
  */
 static void bi_flush(deflate_state *s) {
-    if (s->bi_valid == 64) {
-        put_uint64(s, s->bi_buf);
-        s->bi_buf = 0;
-        s->bi_valid = 0;
-    } else {
-        if (s->bi_valid >= 32) {
-            put_uint32(s, (uint32_t)s->bi_buf);
-            s->bi_buf >>= 32;
-            s->bi_valid -= 32;
-        }
-        if (s->bi_valid >= 16) {
-            put_short(s, (uint16_t)s->bi_buf);
-            s->bi_buf >>= 16;
-            s->bi_valid -= 16;
-        }
-        if (s->bi_valid >= 8) {
-            put_byte(s, s->bi_buf);
-            s->bi_buf >>= 8;
-            s->bi_valid -= 8;
-        }
+    if (s->bi_valid >= 48) {
+        put_uint32(s, (uint32_t)s->bi_buf);
+        put_short(s, (uint16_t)(s->bi_buf >> 32));
+        s->bi_buf >>= 48;
+        s->bi_valid -= 48;
+    } else if (s->bi_valid >= 32) {
+        put_uint32(s, (uint32_t)s->bi_buf);
+        s->bi_buf >>= 32;
+        s->bi_valid -= 32;
+    }
+    if (s->bi_valid >= 16) {
+        put_short(s, (uint16_t)s->bi_buf);
+        s->bi_buf >>= 16;
+        s->bi_valid -= 16;
+    }
+    if (s->bi_valid >= 8) {
+        put_byte(s, s->bi_buf);
+        s->bi_buf >>= 8;
+        s->bi_valid -= 8;
     }
 }