ruby-changes:43081
From: naruse <ko1@a...>
Date: Wed, 25 May 2016 13:21:44 +0900 (JST)
Subject: [ruby-changes:43081] naruse:r55154 (trunk): * regcomp.c (compile_length_tree): return error code immediately
naruse 2016-05-25 13:21:31 +0900 (Wed, 25 May 2016) New Revision: 55154 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55154 Log: * regcomp.c (compile_length_tree): return error code immediately if compile_length_tree raised error [Bug #12418] Modified files: trunk/ChangeLog trunk/regcomp.c trunk/test/ruby/test_regexp.rb Index: regcomp.c =================================================================== --- regcomp.c (revision 55153) +++ regcomp.c (revision 55154) @@ -1592,13 +1592,15 @@ compile_length_tree(Node* node, regex_t* https://github.com/ruby/ruby/blob/trunk/regcomp.c#L1592 case NT_ALT: { - int n; - - n = r = 0; + int n = 0; + len = 0; do { - r += compile_length_tree(NCAR(node), reg); - n++; + r = compile_length_tree(NCAR(node), reg); + if (r < 0) return r; + len += r; + n++; } while (IS_NOT_NULL(node = NCDR(node))); + r = len; r += (SIZE_OP_PUSH + SIZE_OP_JUMP) * (n - 1); } break; Index: ChangeLog =================================================================== --- ChangeLog (revision 55153) +++ ChangeLog (revision 55154) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed May 25 13:10:30 2016 NARUSE, Yui <naruse@r...> + + * regcomp.c (compile_length_tree): return error code immediately + if compile_length_tree raised error [Bug #12418] + Wed May 25 08:01:39 2016 Martin Duerst <duerst@i...> * enc/unicode.c: Fix flag error for switch from titlecase to lowercase. Index: test/ruby/test_regexp.rb =================================================================== --- test/ruby/test_regexp.rb (revision 55153) +++ test/ruby/test_regexp.rb (revision 55154) @@ -1078,6 +1078,9 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1078 conds = {"xy"=>true, "yx"=>true, "xx"=>false, "yy"=>false} assert_match_each(/\A((x)|(y))(?(2)y|x)\z/, conds, bug8583) assert_match_each(/\A((?<x>x)|(?<y>y))(?(<x>)y|x)\z/, conds, bug8583) + + bug12418 = '[ruby-core:75694] [Bug #12418]' + assert_raise(RegexpError, bug12418){ Regexp.new('(0?0|(?(5)||)|(?(5)||))?') } end def test_options_in_look_behind -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/