]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Misc Fixes
authorW. Felix Handte <w@felixhandte.com>
Thu, 14 Jun 2018 19:53:46 +0000 (15:53 -0400)
committerW. Felix Handte <w@felixhandte.com>
Tue, 19 Jun 2018 17:01:21 +0000 (13:01 -0400)
lib/compress/zstd_opt.c

index 974802e174f313783a359aef632fdb07db391f6c..8d90ee7ff42ecc1bb21514cc87846cac2f82235c 100644 (file)
@@ -547,7 +547,9 @@ U32 ZSTD_insertBtAndGetAllMatches (
                     repLen = (U32)ZSTD_count(ip+minMatch, ip+minMatch-repOffset, iLimit) + minMatch;
                 }
             } else {  /* repIndex < dictLimit || repIndex >= current */
-                const BYTE* const repMatch = dictBase + repIndex;
+                const BYTE* const repMatch = dictMode == ZSTD_dictMatchState ?
+                                             dmsBase + repIndex - dmsIndexDelta :
+                                             dictBase + repIndex;
                 assert(current >= windowLow);
                 if ( dictMode == ZSTD_extDict /* this case only valid in extDict mode */
                   && ( ((repOffset-1) /*intentional overflow*/ < current - windowLow)  /* equivalent to `current > repIndex >= windowLow` */
@@ -557,11 +559,10 @@ U32 ZSTD_insertBtAndGetAllMatches (
                 }
                 if (dictMode == ZSTD_dictMatchState
                   && ( ((repOffset-1) /*intentional overflow*/ < current - windowLow)  /* equivalent to `current > repIndex >= windowLow` */
-                     & (((U32)((dictLimit-1) - repIndex) >= 3) ) /* intentional overflow : do not test positions overlapping 2 memory segments */)) {
-                    const BYTE* const repMatch = dmsBase + repIndex - dmsIndexDelta;
-                    if (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch)) {
-                        repLen = (U32)ZSTD_count_2segments(ip+minMatch, repMatch+minMatch, iLimit, dmsEnd, prefixStart) + minMatch;
-            }   }   }
+                     & (((U32)((dictLimit-1) - repIndex) >= 3) ) /* intentional overflow : do not test positions overlapping 2 memory segments */)
+                  && (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch)) ) {
+                    repLen = (U32)ZSTD_count_2segments(ip+minMatch, repMatch+minMatch, iLimit, dmsEnd, prefixStart) + minMatch;
+            }   }
             /* save longer solution */
             if (repLen > bestLength) {
                 DEBUGLOG(8, "found repCode %u (ll0:%u, offset:%u) of length %u",
@@ -577,7 +578,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
 
     /* HC3 match finder */
     if ((mls == 3) /*static*/ && (bestLength < mls)) {
-        U32 const matchIndex3 = ZSTD_insertAndFindFirstIndexHash3(ms, ip);
+        U32 matchIndex3 = ZSTD_insertAndFindFirstIndexHash3(ms, ip);
         if ((matchIndex3 > windowLow)
           & (current - matchIndex3 < (1<<18)) /*heuristic : longer distance likely too expensive*/ ) {
             size_t mlen;
@@ -615,7 +616,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
                 const BYTE* const match = dmsBase + dmsMatchIndex3;
                 size_t mlen = ZSTD_count_2segments(ip, match, iLimit, dmsEnd, prefixStart);
                 if (mlen >= mls) {
-                    U32 const matchIndex3 = dmsMatchIndex3 + dmsIndexDelta;
+                    matchIndex3 = dmsMatchIndex3 + dmsIndexDelta;
                     DEBUGLOG(8, "found small dms match with hlog3, of length %u",
                                 (U32)mlen);
                     bestLength = mlen;
@@ -642,7 +643,7 @@ U32 ZSTD_insertBtAndGetAllMatches (
         const BYTE* match;
         assert(current > matchIndex);
 
-        if ((dictMode == ZSTD_noDict) || (matchIndex+matchLength >= dictLimit)) {
+        if ((dictMode == ZSTD_noDict) || (dictMode == ZSTD_dictMatchState) || (matchIndex+matchLength >= dictLimit)) {
             assert(matchIndex+matchLength >= dictLimit);  /* ensure the condition is correct when !extDict */
             match = base + matchIndex;
             matchLength += ZSTD_count(ip+matchLength, match+matchLength, iLimit);