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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
38a9831caa
commit
78b1ca9f0f
2
array.c
2
array.c
@ -735,12 +735,14 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = NUM2LONG(size);
|
len = NUM2LONG(size);
|
||||||
|
/* NUM2LONG() may call size.to_int, ary can be frozen, modified, etc */
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
rb_raise(rb_eArgError, "negative array size");
|
rb_raise(rb_eArgError, "negative array size");
|
||||||
}
|
}
|
||||||
if (len > ARY_MAX_SIZE) {
|
if (len > ARY_MAX_SIZE) {
|
||||||
rb_raise(rb_eArgError, "array size too big");
|
rb_raise(rb_eArgError, "array size too big");
|
||||||
}
|
}
|
||||||
|
/* recheck after argument conversion */
|
||||||
rb_ary_modify(ary);
|
rb_ary_modify(ary);
|
||||||
ary_resize_capa(ary, len);
|
ary_resize_capa(ary, len);
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user