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

ruby-changes:32776

From: nobu <ko1@a...>
Date: Thu, 6 Feb 2014 10:31:31 +0900 (JST)
Subject: [ruby-changes:32776] nobu:r44855 (trunk): array.c: comment why rb_ary_modify is needed twice

nobu	2014-02-06 10:31:27 +0900 (Thu, 06 Feb 2014)

  New Revision: 44855

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44855

  Log:
    array.c: comment why rb_ary_modify is needed twice
    
    * array.c (rb_ary_initialize): NUM2LONG() may call size.to_int,
      ary can be frozen, modified, etc, so recheck after argument
      conversion is necessary.  [Closes GH-526]

  Modified files:
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 44854)
+++ array.c	(revision 44855)
@@ -735,12 +735,14 @@ rb_ary_initialize(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/array.c#L735
     }
 
     len = NUM2LONG(size);
+    /* NUM2LONG() may call size.to_int, ary can be frozen, modified, etc */
     if (len < 0) {
 	rb_raise(rb_eArgError, "negative array size");
     }
     if (len > ARY_MAX_SIZE) {
 	rb_raise(rb_eArgError, "array size too big");
     }
+    /* recheck after argument conversion */
     rb_ary_modify(ary);
     ary_resize_capa(ary, len);
     if (rb_block_given_p()) {

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

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