From d4c6067d28accf8563ea011ce73a2b48610d6a93 Mon Sep 17 00:00:00 2001 From: Roy Oursler Date: Mon, 26 Sep 2016 16:39:34 -0700 Subject: [PATCH] igzip: Fix bug in default histogram generation Change-Id: Ib1976633c2fbf6f48aeb4b38e73fd75d41c62be5 Signed-off-by: Roy Oursler --- igzip/huff_codes.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/igzip/huff_codes.c b/igzip/huff_codes.c index 8ae4b63..a4cfdec 100644 --- a/igzip/huff_codes.c +++ b/igzip/huff_codes.c @@ -178,9 +178,10 @@ void isal_update_histogram_base(uint8_t * start_stream, int length, literal = *(uint32_t *) current; hash = compute_hash(literal) & HASH_MASK; seen = last_seen[hash]; - last_seen[hash] = (uint64_t) current & 0xFFFF; - dist = ((uint64_t) current - seen) & 0xFFFF; + last_seen[hash] = ((uint64_t) current - (uint64_t) start_stream) & 0xFFFF; + dist = ((uint64_t) current - (uint64_t) start_stream - seen) & 0xFFFF; if (dist - 1 < D - 1) { + assert(start_stream <= current - dist); match_length = compare258(current - dist, current, end_stream - current); if (match_length >= SHORTEST_MATCH) { @@ -196,7 +197,9 @@ void isal_update_histogram_base(uint8_t * start_stream, int length, for (; next_hash < end; next_hash++) { literal = *(uint32_t *) next_hash; hash = compute_hash(literal) & HASH_MASK; - last_seen[hash] = (uint64_t) next_hash & 0xFFFF; + last_seen[hash] = + ((uint64_t) next_hash - + (uint64_t) start_stream) & 0xFFFF; } dist_histogram[convert_dist_to_dist_sym(dist)] += 1; @@ -211,8 +214,8 @@ void isal_update_histogram_base(uint8_t * start_stream, int length, literal = literal >> 8; hash = compute_hash(literal) & HASH_MASK; seen = last_seen[hash]; - last_seen[hash] = (uint64_t) current & 0xFFFF; - dist = ((uint64_t) current - seen) & 0xFFFF; + last_seen[hash] = ((uint64_t) current - (uint64_t) start_stream) & 0xFFFF; + dist = ((uint64_t) current - (uint64_t) start_stream - seen) & 0xFFFF; if (dist < D) { match_length = compare258(current - dist, current, end_stream - current); if (match_length >= SHORTEST_MATCH) {