summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-20 07:38:15 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-20 07:38:15 +0000
commit855e79f3de9dea98f9484181c9ffe47dbcba2807 (patch)
treeea1c13846f56041de08b62f4e351bf9563eb2e5d /array.c
parent594a34bedacc74101e511e5861742cab0694c54e (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_7@17480 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 fda2c24..9814722 100644
--- a/array.c
+++ b/array.c
@@ -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;