From 5003da1f3e22ceeb63212a710707d9e65f7ffcbf Mon Sep 17 00:00:00 2001 From: rhe Date: Fri, 14 Jul 2017 09:41:05 +0000 Subject: hash.c: fix possible crash in Hash#transform_keys! Fix up r59328. It is possible that the given block abuses ObjectSpace.each_object to shrink the temporary array. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 3918fdd532..c47f21ee9f 100644 --- a/hash.c +++ b/hash.c @@ -1865,8 +1865,8 @@ rb_hash_transform_keys(VALUE hash) /* * call-seq: - * hsh.transform_keys! {|value| block } -> hsh - * hsh.transform_keys! -> an_enumerator + * hsh.transform_keys! {|key| block } -> hsh + * hsh.transform_keys! -> an_enumerator * * Invokes the given block once for each key in hsh, replacing it * with the new key returned by the block, and then returns hsh. @@ -1889,8 +1889,8 @@ rb_hash_transform_keys_bang(VALUE hash) long i; VALUE keys = rb_hash_keys(hash); for (i = 0; i < RARRAY_LEN(keys); ++i) { - VALUE new_key = rb_yield(RARRAY_AREF(keys, i)); - rb_hash_aset(hash, new_key, rb_hash_delete(hash, RARRAY_AREF(keys, i))); + VALUE key = RARRAY_AREF(keys, i), new_key = rb_yield(key); + rb_hash_aset(hash, new_key, rb_hash_delete(hash, key)); } } return hash; -- cgit v1.2.3