From 6ef2abe80eab283f2f64ca8706859ca29ab38869 Mon Sep 17 00:00:00 2001 From: Tomasz Kantecki Date: Tue, 19 Dec 2023 10:44:31 +0000 Subject: [PATCH] igzip: fix issues reported by static code analysis compute_dist_code() and compute_dist_icf_code() in huffman.h: Correct `assert(msb >= 1)` to `assert(msb >= 2)`. `msb` cannot be lower than 2 as it would result in corrupt computations. get_dist_code() in huffman.h: Remove dead `if` statement at the beginning of the function. `dist` must be equal 1 or above in this function. Signed-off-by: Tomasz Kantecki --- igzip/huffman.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/igzip/huffman.h b/igzip/huffman.h index bb46752..5b5c359 100644 --- a/igzip/huffman.h +++ b/igzip/huffman.h @@ -104,7 +104,7 @@ static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist, uint32_t code; msb = bsr(dist); - assert(msb >= 1); + assert(msb >= 2); num_extra_bits = msb - 2; extra_bits = dist & ((1 << num_extra_bits) - 1); dist >>= num_extra_bits; @@ -119,8 +119,6 @@ static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist, static inline void get_dist_code(struct isal_hufftables *hufftables, uint32_t dist, uint64_t * code, uint64_t * len) { - if (dist < 1) - dist = 0; assert(dist >= 1); assert(dist <= 32768); if (dist <= IGZIP_DIST_TABLE_SIZE) { @@ -161,7 +159,7 @@ static void compute_dist_icf_code(uint32_t dist, uint32_t * code, uint32_t * ext dist -= 1; msb = bsr(dist); - assert(msb >= 1); + assert(msb >= 2); num_extra_bits = msb - 2; *extra_bits = dist & ((1 << num_extra_bits) - 1); dist >>= num_extra_bits;