summaryrefslogtreecommitdiff
path: root/trees.c
diff options
context:
space:
mode:
authorMark Adler <fork@madler.net>2022-10-01 19:55:29 -0700
committerMark Adler <fork@madler.net>2022-10-03 11:42:18 -0700
commit7fabcb53576aca08b8e25174eb7b0df7c585e4e0 (patch)
tree8b626ddb69eeca31639eec2f93d8b6dedfd09536 /trees.c
parent2d6d59e4728a45240c9d238adbeb33032e9eb19d (diff)
downloadzlib-7fabcb53576aca08b8e25174eb7b0df7c585e4e0.tar.gz
Fix bug in block type selection when Z_FIXED used.
A fixed block could be chosen when a stored block was smaller. Now the smaller of the two is always chosen.
Diffstat (limited to 'trees.c')
-rw-r--r--trees.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/trees.c b/trees.c
index 72b521f..340173c 100644
--- a/trees.c
+++ b/trees.c
@@ -950,7 +950,10 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
s->sym_next / 3));
- if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
+#ifndef FORCE_STATIC
+ if (static_lenb <= opt_lenb || s->strategy == Z_FIXED)
+#endif
+ opt_lenb = static_lenb;
} else {
Assert(buf != (char*)0, "lost buf");
@@ -971,11 +974,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
*/
_tr_stored_block(s, buf, stored_len, last);
-#ifdef FORCE_STATIC
- } else if (static_lenb >= 0) { /* force static trees */
-#else
- } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
-#endif
+ } else if (static_lenb == opt_lenb) {
send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree);