diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-08-13 09:21:18 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-08-13 09:21:18 +0000 |
commit | cf5d04f663e9e7a61da4dda66e78097aefe66919 (patch) | |
tree | 431e5afae10458ab9e139683d74724bd713b0ed8 /array.c | |
parent | 510c93caacad0911261f3adeed73b43fc5fca57f (diff) |
* hash.c (rb_hash_replace): should copy ifnone.
* hash.c (rb_hash_dup): should preserve HASH_PROC_DEFAULT and
HASH_DELETED flags.
* hash.c (rb_hash_shift): shift from empty hash should not return
its default proc.
* hash.c (rb_hash_default_proc): new method. [new]
* array.c (rb_ary_aref): no need for Bignum check.
* array.c (rb_ary_aset): explicit Bignum check removd.
* numeric.c (fix_aref): normalize bignum before bit-op.
* bignum.c (rb_big_rand): max may be Bignum zero.
* bignum.c (rb_cstr_to_inum): should normalize bignums, to avoid
returning fixable bignum value.
* bignum.c (rb_uint2big): there should be no zero sized bignum.
* ext/extmk.rb.in: extmake() that works properly for both tkutil
(tk/tkutil.so) and digest/sha1.
* hash.c (rb_hash_equal): should check HASH_PROC_DEFAULT too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -298,16 +298,21 @@ rb_ary_store(ary, idx, val) } if (idx >= RARRAY(ary)->aux.capa) { - long capa_inc = RARRAY(ary)->aux.capa / 2; - if (capa_inc < ARY_DEFAULT_SIZE) { - capa_inc = ARY_DEFAULT_SIZE; + long new_capa = RARRAY(ary)->aux.capa / 2; + + if (new_capa < ARY_DEFAULT_SIZE) { + new_capa = ARY_DEFAULT_SIZE; } - RARRAY(ary)->aux.capa = idx + capa_inc; + new_capa += idx; + if (new_capa > new_capa * (long)sizeof(VALUE)) { + rb_raise(rb_eArgError, "index too big"); + } + RARRAY(ary)->aux.capa = new_capa; REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); } if (idx > RARRAY(ary)->len) { rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len, - idx-RARRAY(ary)->len + 1); + idx-RARRAY(ary)->len + 1); } if (idx >= RARRAY(ary)->len) { @@ -502,9 +507,6 @@ rb_ary_aref(argc, argv, ary) if (FIXNUM_P(arg)) { return rb_ary_entry(ary, FIX2LONG(arg)); } - if (TYPE(arg) == T_BIGNUM) { - rb_raise(rb_eIndexError, "index too big"); - } /* check if idx is Range */ switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) { case Qfalse: @@ -706,9 +708,6 @@ rb_ary_aset(argc, argv, ary) offset = FIX2LONG(argv[0]); goto fixnum; } - if (TYPE(argv[0]) == T_BIGNUM) { - rb_raise(rb_eIndexError, "index too big"); - } if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) { /* check if idx is Range */ rb_ary_update(ary, beg, len, argv[1]); |