]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Adjustments to ldm_calculateMatchRange() to calculate bounds correctly
authorsenhuang42 <senhuang96@fb.com>
Wed, 30 Sep 2020 23:45:40 +0000 (19:45 -0400)
committersenhuang42 <senhuang96@fb.com>
Wed, 7 Oct 2020 17:56:25 +0000 (13:56 -0400)
lib/compress/zstd_opt.c

index 9e38996e397ad343c41169a1cd4f3a70f44e3ce6..5f7466b9b931abed47614eed0751466c10fafa37 100644 (file)
@@ -799,29 +799,29 @@ static void ldm_calculateMatchRange(rawSeqStore_t* ldmSeqStore,
                             U32* matchOffset, U32 currPosInBlock,
                             U32 remainingBytes, U32 currBlockEndPos) {
     rawSeq currSeq = ldmSeqStore->seq[ldmSeqStore->pos];
-    U32 blockPosInSequence = ldmSeqStore->posInSequence + currPosInBlock;
-    U32 literalsBytesLeft = blockPosInSequence < currSeq.litLength ?
-                                currSeq.litLength - blockPosInSequence : 0;
-    /* In this case, the match is further in the block than currPosInBlock */
+    U32 literalsBytesLeft = (ldmSeqStore->posInSequence < currSeq.litLength) ?
+                                    currSeq.litLength - ldmSeqStore->posInSequence :
+                                    0;
+    /* In this case, the match is further in the block than currPosInBlock, and we are
+       currently in the literals section of the LDM */
     if (literalsBytesLeft) {
         if (literalsBytesLeft >= remainingBytes) {
             /* If there are more literal bytes than bytes remaining in block, no ldm */
             *matchStartPosInBlock = UINT_MAX;
             *matchEndPosInBlock = UINT_MAX;
-            ldmSeqStore->pos++;
-            ldmSeqStore->posInSequence = 0;
+            ldm_moveForwardBytesInSeqStore(ldmSeqStore, remainingBytes);
             return;
         }  
     }
 
-    *matchStartPosInBlock = currPosInBlock + literalsBytesLeft;
+    *matchStartPosInBlock = currPosInBlock + currSeq.litLength;
     *matchEndPosInBlock = *matchStartPosInBlock + currSeq.matchLength;
     *matchOffset = currSeq.offset;
 
     /* Match ends after the block ends, we can't use the whole match */
     if (*matchEndPosInBlock > currBlockEndPos) {
         *matchEndPosInBlock = currBlockEndPos;
-        ldmSeqStore->posInSequence += (currBlockEndPos - currPosInBlock);
+        ldm_moveForwardBytesInSeqStore(ldmSeqStore, currBlockEndPos - currPosInBlock);
     } else {
         /* We can use the entire match */
         ldmSeqStore->posInSequence = 0;