Skip to content

Commit 6ef2abe

Browse files
tkanteckmdcornu
authored andcommitted
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 <[email protected]>
1 parent 402bd4f commit 6ef2abe

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

igzip/huffman.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist,
104104
uint32_t code;
105105

106106
msb = bsr(dist);
107-
assert(msb >= 1);
107+
assert(msb >= 2);
108108
num_extra_bits = msb - 2;
109109
extra_bits = dist & ((1 << num_extra_bits) - 1);
110110
dist >>= num_extra_bits;
@@ -119,8 +119,6 @@ static void compute_dist_code(struct isal_hufftables *hufftables, uint16_t dist,
119119
static inline void get_dist_code(struct isal_hufftables *hufftables, uint32_t dist,
120120
uint64_t * code, uint64_t * len)
121121
{
122-
if (dist < 1)
123-
dist = 0;
124122
assert(dist >= 1);
125123
assert(dist <= 32768);
126124
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
161159

162160
dist -= 1;
163161
msb = bsr(dist);
164-
assert(msb >= 1);
162+
assert(msb >= 2);
165163
num_extra_bits = msb - 2;
166164
*extra_bits = dist & ((1 << num_extra_bits) - 1);
167165
dist >>= num_extra_bits;

0 commit comments

Comments
 (0)