diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-20 06:42:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-20 06:42:07 +0000 |
commit | 3db4641b2aa2d3c8b2467786f0442cda84c88f5b (patch) | |
tree | fdea5b0ac377c99cbb1b817436385fc22e60af6c /array.c | |
parent | 2c4fdd3ca618e842729fc1e1b3287b94092a96bf (diff) |
* array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
behavior at integer overflow.
* string.c (str_buf_cat): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -391,7 +391,7 @@ rb_ary_store(ary, idx, val) if (new_capa < ARY_DEFAULT_SIZE) { new_capa = ARY_DEFAULT_SIZE; } - else if (new_capa >= ARY_MAX_SIZE - idx) { + if (new_capa >= ARY_MAX_SIZE - idx) { new_capa = (ARY_MAX_SIZE - idx) / 2; } new_capa += idx; @@ -1094,10 +1094,10 @@ rb_ary_splice(ary, beg, len, rpl) rb_ary_modify(ary); if (beg >= RARRAY(ary)->len) { - len = beg + rlen; - if (len < 0 || len > ARY_MAX_SIZE) { + if (beg > ARY_MAX_SIZE - rlen) { rb_raise(rb_eIndexError, "index %ld too big", beg); } + len = beg + rlen; if (len >= RARRAY(ary)->aux.capa) { REALLOC_N(RARRAY(ary)->ptr, VALUE, len); RARRAY(ary)->aux.capa = len; |