]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix Off-By-One Error in Counting DDS Search Attempts
authorW. Felix Handte <w@felixhandte.com>
Mon, 17 Aug 2020 21:43:01 +0000 (17:43 -0400)
committerW. Felix Handte <w@felixhandte.com>
Thu, 10 Sep 2020 22:51:52 +0000 (18:51 -0400)
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.

lib/compress/zstd_lazy.c

index 0ee9f6506cf04928c9f9e4be00b594afca1e34a3..5e38e49cc6937ff59577b26ad70dc635ee755af0 100644 (file)
@@ -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];