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 | e1a45b10b6165c8fec505180a52c4ce58fb21e91 (patch) | |
tree | a957464b0296925ad853bef9e9ed67a612ae9774 /array.c | |
parent | 72dd5fdc47e1ec78055cd4028b032ea62d50d8c9 (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/trunk@17472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -383,7 +383,7 @@ rb_ary_store(VALUE ary, long idx, VALUE 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; @@ -986,10 +986,10 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl) } rb_ary_modify(ary); if (beg >= RARRAY_LEN(ary)) { - 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 >= ARY_CAPA(ary)) { RESIZE_CAPA(ary, len); } |