1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
tmm1 2013-12-09 10:06:49 +00:00
parent 5dc77048a3
commit a111923062
3 changed files with 17 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Mon Dec 9 18:50:43 2013 Aman Gupta <ruby@tmm1.net>
* 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@atdot.net> Mon Dec 9 18:10:10 2013 Koichi Sasada <ko1@atdot.net>
* vm.c (vm_stat): renamed from ruby_vm_stat. * vm.c (vm_stat): renamed from ruby_vm_stat.

2
hash.c
View file

@ -1414,7 +1414,7 @@ rb_hash_replace(VALUE hash, VALUE hash2)
table2 = RHASH(hash2)->ntbl; table2 = RHASH(hash2)->ntbl;
rb_hash_clear(hash); 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); rb_hash_foreach(hash2, replace_i, hash);
return hash; return hash;

View file

@ -592,6 +592,16 @@ class TestHash < Test::Unit::TestCase
assert_nil(h[2]) assert_nil(h[2])
end 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 def test_shift
h = @h.dup h = @h.dup