Integrate from mainperl.
[p5sagit/p5-mst-13.2.git] / regexec.c
index 9c1243e..f53567e 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -329,7 +329,7 @@ regexec_flags(register regexp *prog, char *stringarg, register char *strend,
 
     /* Check validity of program. */
     if (UCHARAT(prog->program) != REG_MAGIC) {
-       FAIL("corrupted regexp program");
+       croak("corrupted regexp program");
     }
 
     PL_reg_flags = 0;
@@ -1172,6 +1172,12 @@ regmatch(regnode *prog)
            int docolor = *PL_colors[0];
            int taill = (docolor ? 10 : 7); /* 3 chars for "> <" */
            int l = (PL_regeol - locinput > taill ? taill : PL_regeol - locinput);
+           /* The part of the string before starttry has one color
+              (pref0_len chars), between starttry and current
+              position another one (pref_len - pref0_len chars),
+              after the current position the third one.
+              We assume that pref0_len <= pref_len, otherwise we
+              decrease pref0_len.  */
            int pref_len = (locinput - PL_bostr > (5 + taill) - l 
                            ? (5 + taill) - l : locinput - PL_bostr);
            int pref0_len = pref_len  - (locinput - PL_reg_starttry);
@@ -1181,6 +1187,8 @@ regmatch(regnode *prog)
                      ? (5 + taill) - pref_len : PL_regeol - locinput);
            if (pref0_len < 0)
                pref0_len = 0;
+           if (pref0_len > pref_len)
+               pref0_len = pref_len;
            regprop(prop, scan);
            PerlIO_printf(Perl_debug_log, 
                          "%4i <%s%.*s%s%s%.*s%s%s%s%.*s%s>%*s|%3d:%*s%s\n",
@@ -2437,7 +2445,7 @@ regmatch(regnode *prog)
        default:
            PerlIO_printf(PerlIO_stderr(), "%lx %d\n",
                          (unsigned long)scan, OP(scan));
-           FAIL("regexp memory corruption");
+           croak("regexp memory corruption");
        }
        scan = next;
     }
@@ -2446,7 +2454,7 @@ regmatch(regnode *prog)
     * We get here only if there's trouble -- normally "case END" is
     * the terminating point.
     */
-    FAIL("corrupted regexp pointers");
+    croak("corrupted regexp pointers");
     /*NOTREACHED*/
     sayNO;