summaryrefslogtreecommitdiff
path: root/regcomp.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-03-30 09:59:47 +0200
committerYves Orton <demerphq@gmail.com>2022-04-08 12:29:21 +0800
commitdf12890b5e8c018402acec9b116df5182514fae1 (patch)
tree04412b033fdb9a1c363798494af120612c0c8c69 /regcomp.c
parent8ec963d3eca5bc665f5b8d734b102c6a773bc02a (diff)
downloadperl-df12890b5e8c018402acec9b116df5182514fae1.tar.gz
regcomp.c: fix substring optimizer for ACCEPT inside of CURLY
ACCEPT essentially overrides quantifiers larger than 1. Eg, /(A){2}/ has a mincount of 2 and a maxcount of 2, and a minlen of 2 for "AA". But /(A(*ACCEPT)){2}/ should actually have a mincount of 1, and a minlen of 1 as it can match 'A'. In the regex engine proper this doesn't matter, we just do the right thing. But in the optimizer it matters. This patch sets the mincount to 1 in such cases whenever the contents contains an ACCEPT. Thanks for Hugo for asking the questions that lead to this patch.
Diffstat (limited to 'regcomp.c')
-rw-r--r--regcomp.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/regcomp.c b/regcomp.c
index d8bf6876db..a43a6306d7 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -5681,6 +5681,11 @@ S_study_chunk(pTHX_
: f)
, depth+1, mutate_ok);
+ if (data && data->flags & SCF_SEEN_ACCEPT) {
+ if (mincount > 1)
+ mincount = 1;
+ }
+
if (flags & SCF_DO_STCLASS)
data->start_class = oclass;
if (mincount == 0 || minnext == 0) {