Skip to content

Commit

Permalink
[perl #130522] don't try to find_by_class outside the string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hvds committed Jan 11, 2017
1 parent 6785390 commit dda0191
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit dda0191

Please sign in to comment.