]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Silence a warning from Coverity static analysis
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 19 Apr 2024 19:04:21 +0000 (22:04 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Sat, 20 Apr 2024 09:09:37 +0000 (12:09 +0300)
It is logical why it cannot know for sure that the value has
to be at most 4 if it is less than 16.

The x86 filter is based on a very old LZMA SDK version. Newer
ones have quite a different implementation for the same filter.

Thanks to Sam James.

src/liblzma/simple/x86.c

index 10d70e91697b3c599308bc1d5bd3306613e16e40..a5d33264e24226624bc1ce89c327e62bf66c5f07 100644 (file)
@@ -26,11 +26,10 @@ static size_t
 x86_code(void *simple_ptr, uint32_t now_pos, bool is_encoder,
                uint8_t *buffer, size_t size)
 {
-       static const bool MASK_TO_ALLOWED_STATUS[8]
-               = { true, true, true, false, true, false, false, false };
+       static const bool MASK_TO_ALLOWED_STATUS[5]
+                       = { true, true, true, false, true };
 
-       static const uint32_t MASK_TO_BIT_NUMBER[8]
-                       = { 0, 1, 2, 2, 3, 3, 3, 3 };
+       static const uint32_t MASK_TO_BIT_NUMBER[5] = { 0, 1, 2, 2, 3 };
 
        lzma_simple_x86 *simple = simple_ptr;
        uint32_t prev_mask = simple->prev_mask;
@@ -67,9 +66,8 @@ x86_code(void *simple_ptr, uint32_t now_pos, bool is_encoder,
 
                b = buffer[buffer_pos + 4];
 
-               if (Test86MSByte(b)
-                       && MASK_TO_ALLOWED_STATUS[(prev_mask >> 1) & 0x7]
-                               && (prev_mask >> 1) < 0x10) {
+               if (Test86MSByte(b) && (prev_mask >> 1) <= 4
+                       && MASK_TO_ALLOWED_STATUS[(prev_mask >> 1)]) {
 
                        uint32_t src = ((uint32_t)(b) << 24)
                                | ((uint32_t)(buffer[buffer_pos + 3]) << 16)