summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
context:
space:
mode:
authorHugo van der Sanden <hv@crypt.org>2001-08-16 17:27:49 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2001-08-17 01:50:55 +0000
commitf31a99c85a958352599ea1e9ed74866c8666a515 (patch)
tree190ccb02aac8f6a9e4839e0b9bb51a26f60a0da7 /regexec.c
parent0af80b6034aad516a126a9414dadccac4de7f9dc (diff)
downloadperl-f31a99c85a958352599ea1e9ed74866c8666a515.tar.gz
Re: [ID 20010803.016] Possible regex bug in 5.6.1
Message-Id: <200108161527.f7GFRnH09419@crypt.compulink.co.uk> p4raw-id: //depot/perl@11697
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/regexec.c b/regexec.c
index e95bd16710..3f062ed798 100644
--- a/regexec.c
+++ b/regexec.c
@@ -3033,12 +3033,15 @@ S_regmatch(pTHX_ regnode *prog)
minmod = 0;
if (ln && regrepeat_hard(scan, ln, &l) < ln)
sayNO;
- if (ln && l == 0 && n >= ln
- /* In fact, this is tricky. If paren, then the
- fact that we did/didnot match may influence
- future execution. */
- && !(paren && ln == 0))
- ln = n;
+ /* if we matched something zero-length we don't need to
+ backtrack - capturing parens are already defined, so
+ the caveat in the maximal case doesn't apply
+
+ XXXX if ln == 0, we can redo this check first time
+ through the following loop
+ */
+ if (ln && l == 0)
+ n = ln; /* don't backtrack */
locinput = PL_reginput;
if (PL_regkind[(U8)OP(next)] == EXACT) {
c1 = (U8)*STRING(next);
@@ -3060,7 +3063,7 @@ S_regmatch(pTHX_ regnode *prog)
UCHARAT(PL_reginput) == c2)
{
if (paren) {
- if (n) {
+ if (ln) {
PL_regstartp[paren] =
HOPc(PL_reginput, -l) - PL_bostr;
PL_regendp[paren] = PL_reginput - PL_bostr;
@@ -3084,12 +3087,13 @@ S_regmatch(pTHX_ regnode *prog)
}
else {
n = regrepeat_hard(scan, n, &l);
- if (n != 0 && l == 0
- /* In fact, this is tricky. If paren, then the
- fact that we did/didnot match may influence
- future execution. */
- && !(paren && ln == 0))
- ln = n;
+ /* if we matched something zero-length we don't need to
+ backtrack, unless the minimum count is zero and we
+ are capturing the result - in that case the capture
+ being defined or not may affect later execution
+ */
+ if (n != 0 && l == 0 && !(paren && ln == 0))
+ ln = n; /* don't backtrack */
locinput = PL_reginput;
DEBUG_r(
PerlIO_printf(Perl_debug_log,