From a1119230621d3ab26e93466a6838be42aaa83307 Mon Sep 17 00:00:00 2001 From: tmm1 Date: Mon, 9 Dec 2013 10:06:49 +0000 Subject: 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ hash.c | 2 +- test/ruby/test_hash.rb | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7801aae5af..87dc95d8cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Dec 9 18:50:43 2013 Aman Gupta + + * 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 * vm.c (vm_stat): renamed from ruby_vm_stat. diff --git a/hash.c b/hash.c index 53d70f9fe7..a6944770a6 100644 --- a/hash.c +++ b/hash.c @@ -1414,7 +1414,7 @@ rb_hash_replace(VALUE hash, VALUE hash2) 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; diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 0593785148..afb0ca4805 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -592,6 +592,16 @@ class TestHash < Test::Unit::TestCase 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 -- cgit v1.2.3