mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
594a34beda
commit
855e79f3de
4 changed files with 34 additions and 37 deletions
|
|
@ -1,3 +1,10 @@
|
|||
Fri Jun 20 16:33:09 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_store, rb_ary_splice): not depend on unspecified
|
||||
behavior at integer overflow.
|
||||
|
||||
* string.c (str_buf_cat): ditto.
|
||||
|
||||
Wed Jun 18 22:24:46 2008 URABE Shyouhei <shyouhei@ruby-lang.org>
|
||||
|
||||
* array.c (ary_new, rb_ary_initialize, rb_ary_store,
|
||||
|
|
|
|||
6
array.c
6
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;
|
||||
|
|
|
|||
56
string.c
56
string.c
|
|
@ -702,18 +702,14 @@ rb_str_resize(str, len)
|
|||
return str;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_str_buf_cat(str, ptr, len)
|
||||
static VALUE
|
||||
str_buf_cat(str, ptr, len)
|
||||
VALUE str;
|
||||
const char *ptr;
|
||||
long len;
|
||||
{
|
||||
long capa, total;
|
||||
|
||||
if (len == 0) return str;
|
||||
if (len < 0) {
|
||||
rb_raise(rb_eArgError, "negative string size (or size too big)");
|
||||
}
|
||||
rb_str_modify(str);
|
||||
if (FL_TEST(str, STR_ASSOC)) {
|
||||
FL_UNSET(str, STR_ASSOC);
|
||||
|
|
@ -722,9 +718,16 @@ rb_str_buf_cat(str, ptr, len)
|
|||
else {
|
||||
capa = RSTRING(str)->aux.capa;
|
||||
}
|
||||
if (RSTRING(str)->len >= LONG_MAX - len) {
|
||||
rb_raise(rb_eArgError, "string sizes too big");
|
||||
}
|
||||
total = RSTRING(str)->len+len;
|
||||
if (capa <= total) {
|
||||
while (total > capa) {
|
||||
if (capa + 1 >= LONG_MAX / 2) {
|
||||
capa = total;
|
||||
break;
|
||||
}
|
||||
capa = (capa + 1) * 2;
|
||||
}
|
||||
RESIZE_CAPA(str, capa);
|
||||
|
|
@ -736,6 +739,19 @@ rb_str_buf_cat(str, ptr, len)
|
|||
return str;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_str_buf_cat(str, ptr, len)
|
||||
VALUE str;
|
||||
const char *ptr;
|
||||
long len;
|
||||
{
|
||||
if (len == 0) return str;
|
||||
if (len < 0) {
|
||||
rb_raise(rb_eArgError, "negative string size (or size too big)");
|
||||
}
|
||||
return str_buf_cat(str, ptr, len);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_str_buf_cat2(str, ptr)
|
||||
VALUE str;
|
||||
|
|
@ -777,33 +793,7 @@ VALUE
|
|||
rb_str_buf_append(str, str2)
|
||||
VALUE str, str2;
|
||||
{
|
||||
long capa, len;
|
||||
|
||||
rb_str_modify(str);
|
||||
if (FL_TEST(str, STR_ASSOC)) {
|
||||
FL_UNSET(str, STR_ASSOC);
|
||||
capa = RSTRING(str)->aux.capa = RSTRING(str)->len;
|
||||
}
|
||||
else {
|
||||
capa = RSTRING(str)->aux.capa;
|
||||
}
|
||||
len = RSTRING(str)->len+RSTRING(str2)->len;
|
||||
if (len < 0 || (capa+1) > LONG_MAX / 2) {
|
||||
rb_raise(rb_eArgError, "string sizes too big");
|
||||
}
|
||||
if (capa <= len) {
|
||||
while (len > capa) {
|
||||
capa = (capa + 1) * 2;
|
||||
}
|
||||
RESIZE_CAPA(str, capa);
|
||||
}
|
||||
memcpy(RSTRING(str)->ptr + RSTRING(str)->len,
|
||||
RSTRING(str2)->ptr, RSTRING(str2)->len);
|
||||
RSTRING(str)->len += RSTRING(str2)->len;
|
||||
RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; /* sentinel */
|
||||
OBJ_INFECT(str, str2);
|
||||
|
||||
return str;
|
||||
return str_buf_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define RUBY_RELEASE_DATE "2008-06-20"
|
||||
#define RUBY_VERSION_CODE 187
|
||||
#define RUBY_RELEASE_CODE 20080620
|
||||
#define RUBY_PATCHLEVEL 20
|
||||
#define RUBY_PATCHLEVEL 21
|
||||
|
||||
#define RUBY_VERSION_MAJOR 1
|
||||
#define RUBY_VERSION_MINOR 8
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue