diff options
Diffstat (limited to 'C/LzFind.c')
| -rw-r--r-- | C/LzFind.c | 24 |
1 files changed, 12 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* LzFind.c -- Match finder for LZ algorithms | 1 | /* LzFind.c -- Match finder for LZ algorithms |
| 2 | 2024-03-01 : Igor Pavlov : Public domain */ | 2 | : Igor Pavlov : Public domain */ |
| 3 | 3 | ||
| 4 | #include "Precomp.h" | 4 | #include "Precomp.h" |
| 5 | 5 | ||
| @@ -404,7 +404,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, | |||
| 404 | const unsigned nbMax = | 404 | const unsigned nbMax = |
| 405 | (p->numHashBytes == 2 ? 16 : | 405 | (p->numHashBytes == 2 ? 16 : |
| 406 | (p->numHashBytes == 3 ? 24 : 32)); | 406 | (p->numHashBytes == 3 ? 24 : 32)); |
| 407 | if (numBits > nbMax) | 407 | if (numBits >= nbMax) |
| 408 | numBits = nbMax; | 408 | numBits = nbMax; |
| 409 | if (numBits >= 32) | 409 | if (numBits >= 32) |
| 410 | hs = (UInt32)0 - 1; | 410 | hs = (UInt32)0 - 1; |
| @@ -416,14 +416,14 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, | |||
| 416 | hs |= (256 << kLzHash_CrcShift_2) - 1; | 416 | hs |= (256 << kLzHash_CrcShift_2) - 1; |
| 417 | { | 417 | { |
| 418 | const UInt32 hs2 = MatchFinder_GetHashMask2(p, historySize); | 418 | const UInt32 hs2 = MatchFinder_GetHashMask2(p, historySize); |
| 419 | if (hs > hs2) | 419 | if (hs >= hs2) |
| 420 | hs = hs2; | 420 | hs = hs2; |
| 421 | } | 421 | } |
| 422 | hsCur = hs; | 422 | hsCur = hs; |
| 423 | if (p->expectedDataSize < historySize) | 423 | if (p->expectedDataSize < historySize) |
| 424 | { | 424 | { |
| 425 | const UInt32 hs2 = MatchFinder_GetHashMask2(p, (UInt32)p->expectedDataSize); | 425 | const UInt32 hs2 = MatchFinder_GetHashMask2(p, (UInt32)p->expectedDataSize); |
| 426 | if (hsCur > hs2) | 426 | if (hsCur >= hs2) |
| 427 | hsCur = hs2; | 427 | hsCur = hs2; |
| 428 | } | 428 | } |
| 429 | } | 429 | } |
| @@ -434,7 +434,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, | |||
| 434 | if (p->expectedDataSize < historySize) | 434 | if (p->expectedDataSize < historySize) |
| 435 | { | 435 | { |
| 436 | hsCur = MatchFinder_GetHashMask(p, (UInt32)p->expectedDataSize); | 436 | hsCur = MatchFinder_GetHashMask(p, (UInt32)p->expectedDataSize); |
| 437 | if (hsCur > hs) // is it possible? | 437 | if (hsCur >= hs) // is it possible? |
| 438 | hsCur = hs; | 438 | hsCur = hs; |
| 439 | } | 439 | } |
| 440 | } | 440 | } |
| @@ -890,7 +890,7 @@ static UInt32 * Hc_GetMatchesSpec(size_t lenLimit, UInt32 curMatch, UInt32 pos, | |||
| 890 | return d; | 890 | return d; |
| 891 | { | 891 | { |
| 892 | const Byte *pb = cur - delta; | 892 | const Byte *pb = cur - delta; |
| 893 | curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)]; | 893 | curMatch = son[_cyclicBufferPos - delta + (_cyclicBufferPos < delta ? _cyclicBufferSize : 0)]; |
| 894 | if (pb[maxLen] == cur[maxLen] && *pb == *cur) | 894 | if (pb[maxLen] == cur[maxLen] && *pb == *cur) |
| 895 | { | 895 | { |
| 896 | UInt32 len = 0; | 896 | UInt32 len = 0; |
| @@ -925,7 +925,7 @@ static UInt32 * Hc_GetMatchesSpec(size_t lenLimit, UInt32 curMatch, UInt32 pos, | |||
| 925 | break; | 925 | break; |
| 926 | { | 926 | { |
| 927 | ptrdiff_t diff; | 927 | ptrdiff_t diff; |
| 928 | curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)]; | 928 | curMatch = son[_cyclicBufferPos - delta + (_cyclicBufferPos < delta ? _cyclicBufferSize : 0)]; |
| 929 | diff = (ptrdiff_t)0 - (ptrdiff_t)delta; | 929 | diff = (ptrdiff_t)0 - (ptrdiff_t)delta; |
| 930 | if (cur[maxLen] == cur[(ptrdiff_t)maxLen + diff]) | 930 | if (cur[maxLen] == cur[(ptrdiff_t)maxLen + diff]) |
| 931 | { | 931 | { |
| @@ -972,7 +972,7 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt | |||
| 972 | // if (curMatch >= pos) { *ptr0 = *ptr1 = kEmptyHashValue; return NULL; } | 972 | // if (curMatch >= pos) { *ptr0 = *ptr1 = kEmptyHashValue; return NULL; } |
| 973 | 973 | ||
| 974 | cmCheck = (UInt32)(pos - _cyclicBufferSize); | 974 | cmCheck = (UInt32)(pos - _cyclicBufferSize); |
| 975 | if ((UInt32)pos <= _cyclicBufferSize) | 975 | if ((UInt32)pos < _cyclicBufferSize) |
| 976 | cmCheck = 0; | 976 | cmCheck = 0; |
| 977 | 977 | ||
| 978 | if (cmCheck < curMatch) | 978 | if (cmCheck < curMatch) |
| @@ -980,7 +980,7 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt | |||
| 980 | { | 980 | { |
| 981 | const UInt32 delta = pos - curMatch; | 981 | const UInt32 delta = pos - curMatch; |
| 982 | { | 982 | { |
| 983 | CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); | 983 | CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + (_cyclicBufferPos < delta ? _cyclicBufferSize : 0)) << 1); |
| 984 | const Byte *pb = cur - delta; | 984 | const Byte *pb = cur - delta; |
| 985 | unsigned len = (len0 < len1 ? len0 : len1); | 985 | unsigned len = (len0 < len1 ? len0 : len1); |
| 986 | const UInt32 pair0 = pair[0]; | 986 | const UInt32 pair0 = pair[0]; |
| @@ -1039,7 +1039,7 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const | |||
| 1039 | UInt32 cmCheck; | 1039 | UInt32 cmCheck; |
| 1040 | 1040 | ||
| 1041 | cmCheck = (UInt32)(pos - _cyclicBufferSize); | 1041 | cmCheck = (UInt32)(pos - _cyclicBufferSize); |
| 1042 | if ((UInt32)pos <= _cyclicBufferSize) | 1042 | if ((UInt32)pos < _cyclicBufferSize) |
| 1043 | cmCheck = 0; | 1043 | cmCheck = 0; |
| 1044 | 1044 | ||
| 1045 | if (// curMatch >= pos || // failure | 1045 | if (// curMatch >= pos || // failure |
| @@ -1048,7 +1048,7 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const | |||
| 1048 | { | 1048 | { |
| 1049 | const UInt32 delta = pos - curMatch; | 1049 | const UInt32 delta = pos - curMatch; |
| 1050 | { | 1050 | { |
| 1051 | CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); | 1051 | CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + (_cyclicBufferPos < delta ? _cyclicBufferSize : 0)) << 1); |
| 1052 | const Byte *pb = cur - delta; | 1052 | const Byte *pb = cur - delta; |
| 1053 | unsigned len = (len0 < len1 ? len0 : len1); | 1053 | unsigned len = (len0 < len1 ? len0 : len1); |
| 1054 | if (pb[len] == cur[len]) | 1054 | if (pb[len] == cur[len]) |
| @@ -1595,7 +1595,7 @@ static void Bt5_MatchFinder_Skip(void *_p, UInt32 num) | |||
| 1595 | UInt32 pos = p->pos; \ | 1595 | UInt32 pos = p->pos; \ |
| 1596 | UInt32 num2 = num; \ | 1596 | UInt32 num2 = num; \ |
| 1597 | /* (p->pos == p->posLimit) is not allowed here !!! */ \ | 1597 | /* (p->pos == p->posLimit) is not allowed here !!! */ \ |
| 1598 | { const UInt32 rem = p->posLimit - pos; if (num2 > rem) num2 = rem; } \ | 1598 | { const UInt32 rem = p->posLimit - pos; if (num2 >= rem) num2 = rem; } \ |
| 1599 | num -= num2; \ | 1599 | num -= num2; \ |
| 1600 | { const UInt32 cycPos = p->cyclicBufferPos; \ | 1600 | { const UInt32 cycPos = p->cyclicBufferPos; \ |
| 1601 | son = p->son + cycPos; \ | 1601 | son = p->son + cycPos; \ |
