Fix infinite loop in PatienceDiff

Certain inputs caused an infinite loop because the prior match data
couldn't be used as expected.  Rather than incrementing the match
pointer before looking at an element, do it after, so the loop breaks
when we wrap around to the starting point.

Change-Id: Ieab28bb3485a914eeddc68aa38c256f255dd778c
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-10-10 13:08:50 -07:00
parent be2ddff6a7
commit 7a0c126d5f
1 changed files with 8 additions and 7 deletions

View File

@ -244,7 +244,7 @@ private void insertB(final int tIdx, int ptr) {
private void scanA() {
int ptr = region.beginA;
final int end = region.endA;
int pLast = pBegin - 1;
int pLast = pBegin;
SCAN: while (ptr < end) {
final int tIdx = hash(a, ptr);
@ -276,12 +276,7 @@ private void scanA() {
// fact that pCommon is sorted by B, and its likely that
// matches in A appear in the same order as they do in B.
//
for (int pIdx = pLast + 1;; pIdx++) {
if (pIdx == pEnd)
pIdx = pBegin;
else if (pIdx == pLast)
break;
for (int pIdx = pLast;;) {
final long priorRec = pCommon[pIdx];
final int priorB = bOf(priorRec);
if (bs < priorB)
@ -291,6 +286,12 @@ else if (pIdx == pLast)
pLast = pIdx;
continue SCAN;
}
pIdx++;
if (pIdx == pEnd)
pIdx = pBegin;
if (pIdx == pLast)
break;
}
}