From ee91d26e067c78d37242b4b2ccf3d5d8d3c85b5f Mon Sep 17 00:00:00 2001 From: Vincent Pit Date: Thu, 25 Jun 2009 20:49:49 +0200 Subject: [PATCH] Update RExC_npar and after_freeze correctly after the first branch of a (?| ... ) This fixes RT #59734 : Segfault when using (?|) in regexp. --- regcomp.c | 7 +++++++ t/op/re_tests | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/regcomp.c b/regcomp.c index bc7086f..7e80041 100644 --- 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) diff --git a/t/op/re_tests b/t/op/re_tests index 0c04840..89934fd 100644 --- a/t/op/re_tests +++ b/t/op/re_tests @@ -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-- +(?|(?x)) x y $+{foo} x +(?|(?x)|(?y)) x y $+{foo} x +(?|(?y)|(?x)) x y $+{foo} x +(?)(?|(?x)) x y $+{foo} x + #Bug #41492 (?(DEFINE)(?(?&B)+)(?a))(?&A) a y $& a (?(DEFINE)(?(?&B)+)(?a))(?&A) aa y $& aa -- 2.7.4