aboutsummaryrefslogtreecommitdiffstats
path: root/enumerator.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-30 07:25:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-30 07:25:17 +0000
commit520f0fec9519647e8ae1dfc15756b537fe580d6e (patch)
treefea38ef577848e2b6ac5a1a41df4a3bdad46f57c /enumerator.c
parent59ed302965c5e38526ad33b13d8361859c5e7726 (diff)
downloadruby-520f0fec9519647e8ae1dfc15756b537fe580d6e.tar.gz
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
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/enumerator.c b/enumerator.c
index 242530caec..2e80580dea 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -495,9 +495,9 @@ enumerator_each(int argc, VALUE *argv, VALUE obj)
static VALUE
enumerator_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, m))
{
- VALUE *memo = (VALUE *)m;
- VALUE idx = *memo;
- *memo = rb_int_succ(idx);
+ NODE *memo = (NODE *)m;
+ VALUE idx = memo->u1.value;
+ memo->u1.value = rb_int_succ(idx);
if (argc <= 1)
return rb_yield_values(2, val, idx);
@@ -537,7 +537,7 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
memo = INT2FIX(0);
else
memo = rb_to_int(memo);
- return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo);
+ return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0));
}
/*