Misc Fixes

dev
W. Felix Handte 2018-06-14 15:53:46 -04:00
parent ade8586ce6
commit 64348a15f1
1 changed files with 10 additions and 9 deletions

View File

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