From bf103c626c6c0d80580748f6b814ec534614ca52 Mon Sep 17 00:00:00 2001 From: Ivan Zlatanov Date: Fri, 23 Apr 2021 11:01:17 +0300 Subject: [PATCH] Replaced constant MAX_DIST2 with MAX_DIST which takes into account the current window size. --- deflate_medium.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deflate_medium.c b/deflate_medium.c index 582e8b2e..1b10b5fe 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -16,8 +16,6 @@ struct match { uInt orgstart; }; -#define MAX_DIST2 ((1 << MAX_WBITS) - MIN_LOOKAHEAD) - static int tr_tally_dist(deflate_state *s, int distance, int length) { return _tr_tally(s, distance, length); @@ -113,6 +111,7 @@ static void fizzle_matches(deflate_state *s, struct match *current, struct match unsigned char *match, *orig; int changed = 0; struct match c,n; + uInt maxDist; /* step zero: sanity checks */ if (current->match_length <= 1) @@ -142,7 +141,8 @@ static void fizzle_matches(deflate_state *s, struct match *current, struct match n = *next; /* step one: try to move the "next" match to the left as much as possible */ - limit = next->strstart > MAX_DIST2 ? next->strstart - MAX_DIST2 : 0; + maxDist = MAX_DIST(s); + limit = next->strstart > maxDist ? next->strstart - maxDist : 0; match = s->window + n.match_start - 1; orig = s->window + n.strstart - 1; @@ -230,7 +230,7 @@ block_state deflate_medium(deflate_state *s, int flush) * At this point we have always match_length < MIN_MATCH */ - if (hash_head != 0 && s->strstart - hash_head <= MAX_DIST2) { + if (hash_head != 0 && s->strstart - hash_head <= MAX_DIST(s)) { /* To simplify the code, we prevent matches with the string * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). @@ -265,7 +265,7 @@ block_state deflate_medium(deflate_state *s, int flush) /* Find the longest match, discarding those <= prev_length. * At this point we have always match_length < MIN_MATCH */ - if (hash_head != 0 && s->strstart - hash_head <= MAX_DIST2) { + if (hash_head != 0 && s->strstart - hash_head <= MAX_DIST(s)) { /* To simplify the code, we prevent matches with the string * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file).