]> source.dussan.org Git - jgit.git/commitdiff
Fix infinite loop in PatienceDiff 19/1719/1
authorShawn O. Pearce <spearce@spearce.org>
Sun, 10 Oct 2010 20:08:50 +0000 (13:08 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Sun, 10 Oct 2010 21:39:29 +0000 (14:39 -0700)
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>
org.eclipse.jgit/src/org/eclipse/jgit/diff/PatienceDiffIndex.java

index 27cf9252e8a876c65f08f020745afe741b844fd4..042abd2d7165dbc4bebf7b036b1487ea259f4006 100644 (file)
@@ -244,7 +244,7 @@ final class PatienceDiffIndex<S extends Sequence> {
        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 @@ final class PatienceDiffIndex<S extends Sequence> {
                                        // 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 @@ final class PatienceDiffIndex<S extends Sequence> {
                                                        pLast = pIdx;
                                                        continue SCAN;
                                                }
+
+                                               pIdx++;
+                                               if (pIdx == pEnd)
+                                                       pIdx = pBegin;
+                                               if (pIdx == pLast)
+                                                       break;
                                        }
                                }