ruby-changes:32017
From: tmm1 <ko1@a...>
Date: Mon, 9 Dec 2013 19:06:58 +0900 (JST)
Subject: [ruby-changes:32017] tmm1:r44096 (trunk): hash.c: fix segv in Hash#replace
tmm1 2013-12-09 19:06:49 +0900 (Mon, 09 Dec 2013) New Revision: 44096 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44096 Log: hash.c: fix segv in Hash#replace * hash.c (rb_hash_replace): fix segv on `{}.replace({})` introduced in r44060 [Bug #9230] [ruby-core:58991] * test/ruby/test_hash.rb: regression test for above Modified files: trunk/ChangeLog trunk/hash.c trunk/test/ruby/test_hash.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 44095) +++ ChangeLog (revision 44096) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Dec 9 18:50:43 2013 Aman Gupta <ruby@t...> + + * hash.c (rb_hash_replace): fix segv on `{}.replace({})` introduced + in r44060 [Bug #9230] [ruby-core:58991] + * test/ruby/test_hash.rb: regression test for above + Mon Dec 9 18:10:10 2013 Koichi Sasada <ko1@a...> * vm.c (vm_stat): renamed from ruby_vm_stat. Index: hash.c =================================================================== --- hash.c (revision 44095) +++ hash.c (revision 44096) @@ -1414,7 +1414,7 @@ rb_hash_replace(VALUE hash, VALUE hash2) https://github.com/ruby/ruby/blob/trunk/hash.c#L1414 table2 = RHASH(hash2)->ntbl; rb_hash_clear(hash); - hash_tbl(hash)->type = table2->type; + if (table2) hash_tbl(hash)->type = table2->type; rb_hash_foreach(hash2, replace_i, hash); return hash; Index: test/ruby/test_hash.rb =================================================================== --- test/ruby/test_hash.rb (revision 44095) +++ test/ruby/test_hash.rb (revision 44096) @@ -592,6 +592,16 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L592 assert_nil(h[2]) end + def test_replace_bug9230 + h = @cls[] + h.replace(@cls[]) + assert_empty h + + h = @cls[] + h.replace(@cls[].compare_by_identity) + assert_predicate(h, :compare_by_identity?) + end + def test_shift h = @h.dup -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/