This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: regpiece() 0 times anything is 0
authorKarl Williamson <khw@cpan.org>
Fri, 24 Apr 2020 17:27:33 +0000 (11:27 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 12 Oct 2020 15:45:47 +0000 (09:45 -0600)
Prior to this commit, regpiece() gave width to many quantified values.
This is wrong.  If something is zero width, repeating it doesn't cause
it to gain width.  I don't know if this led to wrong pattern matching
results, but I imagine it led to slower results in some cases.

regcomp.c

index 945e444..ed1cb92 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -12640,8 +12640,6 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
     if (op != '{') {
         nextchar(pRExC_state);
 
-        *flagp = HASWIDTH;
-
         if (op == '*') {
             min = 0;
         }
@@ -12748,6 +12746,9 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
         }
     }
 
+    if (max > 0)
+        *flagp |= (flags & HASWIDTH);
+
     if ((flags&SIMPLE)) {
         if (min == 0 && max == REG_INFTY) {
 
@@ -12814,10 +12815,6 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
     }
     FLAGS(REGNODE_p(ret)) = 0;
 
-    if (min > 0)
-        *flagp = 0;
-    if (max > 0)
-        *flagp |= HASWIDTH;
     ARG1_SET(REGNODE_p(ret), (U16)min);
     ARG2_SET(REGNODE_p(ret), (U16)max);
     if (max == REG_INFTY)