This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #130522] don't try to find_by_class outside the string
authorHugo van der Sanden <hv@crypt.org>
Sun, 8 Jan 2017 14:59:36 +0000 (14:59 +0000)
committerHugo van der Sanden <hv@crypt.org>
Wed, 11 Jan 2017 19:41:44 +0000 (19:41 +0000)
If the calculated latest start position to try is before our current
start position, stop immediately: else we can read out of bounds,
and end up doing unnecessary work.

regexec.c

index 6a9da32..7d2a3ac 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -1974,10 +1974,8 @@ S_find_byclass(pTHX_ regexp * prog, const regnode *c, char *s,
          * trying that it will fail; so don't start a match past the
          * required minimum number from the far end */
         e = HOP3c(strend, -((SSize_t)ln), s);
-
-        if (reginfo->intuit && e < s) {
-            e = s;                     /* Due to minlen logic of intuit() */
-        }
+        if (e < s)
+            break;
 
         c1 = *pat_string;
         c2 = fold_array[c1];
@@ -2021,10 +2019,6 @@ S_find_byclass(pTHX_ regexp * prog, const regnode *c, char *s,
          */
         e = HOP3c(strend, -((SSize_t)lnc), s);
 
-        if (reginfo->intuit && e < s) {
-            e = s;                     /* Due to minlen logic of intuit() */
-        }
-
         /* XXX Note that we could recalculate e to stop the loop earlier,
          * as the worst case expansion above will rarely be met, and as we
          * go along we would usually find that e moves further to the left.