summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2023-01-13 18:23:01 +0100
committerYves Orton <demerphq@gmail.com>2023-01-13 20:24:28 +0100
commit61e2c0af14d6f848fd8f2ca85beeeb8363365321 (patch)
treefd216903af873a9ca48385ce53cb413d58ec10a4 /regexec.c
parent1b3de34b7cfc0bdda5cfe9dbb2690bf5b8faeed1 (diff)
downloadperl-61e2c0af14d6f848fd8f2ca85beeeb8363365321.tar.gz
regexec.c - avoid calling regrepeat when the max is 0
When we have a max quantifier of 0, then the quantified item is essentially a NOTHING reop. Regardless, we do not need to call regrepeat, and doing so confuses some of the logic it contains. Simply avoiding calling regrepeat() fixes the underlying issue, and avoids the broken code. This fixes GH Issue #20690.
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/regexec.c b/regexec.c
index a521ae3013..84f2670e6d 100644
--- a/regexec.c
+++ b/regexec.c
@@ -9316,7 +9316,10 @@ NULL
/* avoid taking address of locinput, so it can remain
* a register var */
char *li = locinput;
- ST.count = regrepeat(rex, &li, ST.A, loceol, reginfo, ST.max);
+ if (ST.max)
+ ST.count = regrepeat(rex, &li, ST.A, loceol, reginfo, ST.max);
+ else
+ ST.count = 0;
if (ST.count < ST.min)
sayNO;
SET_locinput(li);
@@ -10058,6 +10061,8 @@ S_regrepeat(pTHX_ regexp *prog, char **startposp, const regnode *p,
unsigned int to_complement = 0; /* Invert the result? */
char_class_number_ classnum;
+ assert(max);
+
PERL_ARGS_ASSERT_REGREPEAT;
/* This routine is structured so that we switch on the input OP. Each OP