]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fizing litLength == 0 case
authorBimba Shrestha <bshrestha.msae@gmail.com>
Tue, 10 Sep 2019 17:06:02 +0000 (10:06 -0700)
committerBimba Shrestha <bshrestha.msae@gmail.com>
Tue, 10 Sep 2019 17:38:13 +0000 (10:38 -0700)
lib/compress/zstd_compress.c

index 56da1664e059904e3d34b2445ad36ae0f71b08b9..83bcb52dd656755ac7f66695aeb4b10d56d46a69 100644 (file)
@@ -2291,11 +2291,22 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
             outSeqs[i].rep = 1;
             repIdx = i - outSeqs[i].offset;
 
+            /* Not first block */
             if (repIdx >= 0) {
-                outSeqs[i].offset = outSeqs[repIdx].offset;
-            }
-
-            if (repIdx == -1) {
+                /* Special case where litLength == 0 */
+                if (outSeqs[i].litLength == 0) {
+                    /* When the offset is 3 */
+                    if (outSeqs[i].offset > 2) {
+                        outSeqs[i].offset = outSeqs[repIdx - 1].offset - 1;
+                    /* When the offset is either 1 or 2 */
+                    } else {
+                        outSeqs[i].offset = outSeqs[repIdx - 1].offset;
+                    }
+                } else {
+                    outSeqs[i].offset = outSeqs[repIdx].offset;
+                }
+            /* First block */
+            } else if (repIdx == -1) {
                 outSeqs[i].offset = 1;
             } else if (repIdx == -2) {
                 outSeqs[i].offset = 4;