From: W. Felix Handte Date: Mon, 17 Aug 2020 21:43:01 +0000 (-0400) Subject: Fix Off-By-One Error in Counting DDS Search Attempts X-Git-Tag: v1.4.7~81^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df386b3d8d50cef611d7f9693417d63620170bd1;p=thirdparty%2Fzstd.git Fix Off-By-One Error in Counting DDS Search Attempts This caused us to double-search the first position and fail to search the last position in the chain, slowing down search and making it less effective. --- diff --git a/lib/compress/zstd_lazy.c b/lib/compress/zstd_lazy.c index 0ee9f6506..5e38e49cc 100644 --- a/lib/compress/zstd_lazy.c +++ b/lib/compress/zstd_lazy.c @@ -575,7 +575,7 @@ size_t ZSTD_HcFindBestMatch_generic ( const U32 ddsMinChain = ddsSize > ddsChainSize ? ddsSize - ddsChainSize : 0; const U32 bucketSize = (1 << DD_BLOG); - U32 attemptNb = 0; + U32 attemptNb = 1; matchIndex = dms->hashTable[ddsIdx]; @@ -603,7 +603,7 @@ size_t ZSTD_HcFindBestMatch_generic ( break; } - if (attemptNb < bucketSize - 1) { + if (attemptNb < bucketSize) { matchIndex = dms->hashTable[ddsIdx + attemptNb]; } else { matchIndex = dms->chainTable[matchIndex & ddsChainMask];