Update RExC_npar and after_freeze correctly after the first branch of a (?| ... )
Vincent Pit [Thu, 25 Jun 2009 18:49:49 +0000 (20:49 +0200)]
This fixes RT #59734 : Segfault when using (?|) in regexp.

regcomp.c
t/op/re_tests

index bc7086f..7e80041 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -6138,6 +6138,13 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
     /* Pick up the branches, linking them together. */
     parse_start = RExC_parse;   /* MJD */
     br = regbranch(pRExC_state, &flags, 1,depth+1);
+
+    if (freeze_paren) {
+        if (RExC_npar > after_freeze)
+            after_freeze = RExC_npar;
+        RExC_npar = freeze_paren;
+    }
+
     /*     branch_len = (paren != 0); */
 
     if (br == NULL)
index 0c04840..89934fd 100644 (file)
@@ -1311,6 +1311,11 @@ X(\w+)(?=\s)|X(\w+)      Xab     y       [$1-$2] [-ab]
 (?|(?|(a)|(b))|(?|(c)|(d)))    d       y       $1      d
 (.)(?|(.)(.)x|(.)d)(.) abcde   y       $1-$2-$3-$4-$5- b-c--e--
 (\N)(?|(\N)(\N)x|(\N)d)(\N)    abcde   y       $1-$2-$3-$4-$5- b-c--e--
+(?|(?<foo>x))  x       y       $+{foo} x
+(?|(?<foo>x)|(?<bar>y))        x       y       $+{foo} x
+(?|(?<bar>y)|(?<foo>x))        x       y       $+{foo} x
+(?<bar>)(?|(?<foo>x))  x       y       $+{foo} x
+
 #Bug #41492
 (?(DEFINE)(?<A>(?&B)+)(?<B>a))(?&A)    a       y       $&      a
 (?(DEFINE)(?<A>(?&B)+)(?<B>a))(?&A)    aa      y       $&      aa