From e1335a307c859f612d666245bf891436da8fdd86 Mon Sep 17 00:00:00 2001 From: eregon Date: Thu, 18 Jul 2013 11:38:01 +0000 Subject: * array.c (rb_ary_count): check length to avoid SEGV while iterating. Remove other pointer loop when arg is given. * test/ruby/test_array.rb (test_count): add test for bug. [ruby-core:56072] [Bug #8654] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_array.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 93ef59a3f5..b158db0ec9 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -572,6 +572,16 @@ class TestArray < Test::Unit::TestCase assert_equal(3, a.count {|x| x % 2 == 1 }) assert_equal(2, a.count(1) {|x| x % 2 == 1 }) assert_raise(ArgumentError) { a.count(0, 1) } + + bug8654 = '[ruby-core:56072]' + assert_in_out_err [], <<-EOS, ["0"], [], bug8654 + a1 = [] + a2 = Array.new(100) { |i| i } + r = a2.count do |i| + p i + a2.replace(a1) if i == 0 + end + EOS end def test_delete -- cgit v1.2.3