From: senhuang42 Date: Wed, 30 Sep 2020 23:45:40 +0000 (-0400) Subject: Adjustments to ldm_calculateMatchRange() to calculate bounds correctly X-Git-Tag: v1.4.7~57^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7348b40a87c61307c026ae5291202f22327059e9;p=thirdparty%2Fzstd.git Adjustments to ldm_calculateMatchRange() to calculate bounds correctly --- diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 9e38996e3..5f7466b9b 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -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;