diff options
author | Yves Orton <demerphq@gmail.com> | 2017-01-27 10:18:51 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2017-01-27 10:23:24 +0100 |
commit | 31fc93954d1f379c7a49889d91436ce99818e1f6 (patch) | |
tree | 80007a1cfc617e32cab63a904d2e40cc595487d8 /regcomp.c | |
parent | cddba0ca094e5b75c25748e7d0e03380aefe5972 (diff) | |
download | perl-31fc93954d1f379c7a49889d91436ce99818e1f6.tar.gz |
fix RT #130561 - recursion and optimising away impossible quantifiers are not friends
Instead of optimising away impossible quantifiers like (foo){1,0} treat them
as unquantified, and guard them with an OPFAIL. Thus /(foo){1,0}/ is treated
the same as /(*FAIL)(foo)/ this is important in patterns like /(foo){1,0}|(?1)/
where the (?1) needs to be able to recurse into the (foo) even though the
(foo){1,0} can never match. It also resolves various issues (SEGVs) with patterns
like /((?1)){1,0}/.
This patch would have been easier if S_reginsert() documented that it is
the callers responsibility to properly set up the NEXT_OFF() of the inserted
node (if the node has a NEXT_OFF())
Diffstat (limited to 'regcomp.c')
-rw-r--r-- | regcomp.c | 14 |
1 files changed, 3 insertions, 11 deletions
@@ -11709,19 +11709,11 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth) nextchar(pRExC_state); if (max < min) { /* If can't match, warn and optimize to fail unconditionally */ - if (SIZE_ONLY) { - - /* We can't back off the size because we have to reserve - * enough space for all the things we are about to throw - * away, but we can shrink it by the amount we are about - * to re-use here */ - RExC_size += PREVOPER(RExC_size) - regarglen[(U8)OPFAIL]; - } - else { + if (PASS2) { ckWARNreg(RExC_parse, "Quantifier {n,m} with n > m can't match"); - RExC_emit = orig_emit; } - ret = reganode(pRExC_state, OPFAIL, 0); + reginsert(pRExC_state, OPFAIL, orig_emit, depth+1); + NEXT_OFF(orig_emit)= regarglen[OPFAIL] + NODE_STEP_REGNODE; return ret; } else if (min == max && *RExC_parse == '?') |