[前][次][番号順一覧][スレッド一覧]

ruby-changes:47219

From: rhe <ko1@a...>
Date: Fri, 14 Jul 2017 18:41:15 +0900 (JST)
Subject: [ruby-changes:47219] rhe:r59334 (trunk): hash.c: fix possible crash in Hash#transform_keys!

rhe	2017-07-14 18:41:05 +0900 (Fri, 14 Jul 2017)

  New Revision: 59334

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59334

  Log:
    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.

  Modified files:
    trunk/hash.c
Index: hash.c
===================================================================
--- hash.c	(revision 59333)
+++ hash.c	(revision 59334)
@@ -1865,8 +1865,8 @@ rb_hash_transform_keys(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1865
 
 /*
  *  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) https://github.com/ruby/ruby/blob/trunk/hash.c#L1889
 	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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]