diff options
author | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-14 09:41:05 +0000 |
---|---|---|
committer | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-14 09:41:05 +0000 |
commit | 677751e1bcd6b08496c5cc734ef8b755e1f47316 (patch) | |
tree | 9a4f86b1cf62929895af467cc3765bb99c2f0a33 /hash.c | |
parent | 7c9c2bc1dd470cd4794d6891b21ee1fc61f401e0 (diff) | |
download | ruby-677751e1bcd6b08496c5cc734ef8b755e1f47316.tar.gz |
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
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -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 <i>hsh</i>, replacing it * with the new key returned by the block, and then returns <i>hsh</i>. @@ -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; |