about summary refs log tree commit diff
path: root/Src/pattern.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/pattern.c')
-rw-r--r--Src/pattern.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/Src/pattern.c b/Src/pattern.c
index b547bdc14..872816d9b 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -2751,22 +2751,26 @@ patmatch(Upat prog)
 		savglobflags = patglobflags;
 		saverrsfound = errsfound;
 		lastcharstart = charstart + (patinput - start);
-		while (no >= min) {
-		    int charmatch_cache;
-		    if (nextch < 0 ||
-			(patinput < patinend &&
-			 CHARMATCH_EXPR(CHARREF(patinput, patinend),
-					nextch))) {
-			if (patmatch(next))
-			    return 1;
+		if (no >= min) {
+		    for (;;) {
+			int charmatch_cache;
+			if (nextch < 0 ||
+			    (patinput < patinend &&
+			     CHARMATCH_EXPR(CHARREF(patinput, patinend),
+					    nextch))) {
+			    if (patmatch(next))
+				return 1;
+			}
+			if (--no < min)
+			    break;
+			/* find start of previous full character */
+			while (!*--lastcharstart)
+			    DPUTS(lastcharstart < charstart,
+				  "lastcharstart invalid");
+			patinput = start + (lastcharstart-charstart);
+			patglobflags = savglobflags;
+			errsfound = saverrsfound;
 		    }
-		    no--;
-		    /* find start of previous full character */
-		    while (!*--lastcharstart)
-			;
-		    patinput = start + (lastcharstart-charstart);
-		    patglobflags = savglobflags;
-		    errsfound = saverrsfound;
 		}
 	    }
 	    /*