From 520f0fec9519647e8ae1dfc15756b537fe580d6e Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 30 Nov 2013 07:25:17 +0000 Subject: enumerator.c: should not store local variable address * enumerator.c (enumerator_with_index): should not store local variable address to memoise the arguments. it is invalidated after the return. [ruby-core:58692] [Bug #9178] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_enumerator.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/ruby/test_enumerator.rb') diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index e1b23792bd..e08edd512c 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -134,6 +134,16 @@ class TestEnumerator < Test::Unit::TestCase assert_raise(TypeError, bug8010){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a } end + def test_with_index_dangling_memo + bug9178 = '[ruby-core:58692] [Bug #9178]' + assert_separately([], <<-"end;") + bug = "#{bug9178}" + e = [1].to_enum(:chunk).with_index {|c,i| i == 5} + assert_kind_of(Enumerator, e) + assert_equal([false, [1]], e.to_a[0], bug) + end; + end + def test_with_object obj = [0, 1] ret = (1..10).each.with_object(obj) {|i, memo| -- cgit v1.2.3