summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-20 06:53:16 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-20 06:53:16 +0000
commitd84dde37a1c13be3360e0ec0f7dfc9c701f4ae5d (patch)
tree3ad3288dd65f78e72997908b004b64ef331cdc4d /array.c
parent38328551f13b17e8205777d3075bffe335eaff90 (diff)
merge revision(s) 17470:17472:
* 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_6@17475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/array.c b/array.c
index 000683fda1..c5261044da 100644
--- a/array.c
+++ b/array.c
@@ -370,7 +370,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;
@@ -979,10 +979,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;