diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-14 00:39:40 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-14 00:39:40 +0000 |
commit | b3d8a4060cb9ab86b28f85ff32c5b4bebd3b6830 (patch) | |
tree | 378495008adb3308afe51a261018db4b147af4ad | |
parent | 4bf4ddb693b885a5ce9b9ad983c4743627ae29cc (diff) |
* string.c (rb_str_concat): raise RangeError when the argument is
negative value. [ruby-core:27583]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 14 |
2 files changed, 17 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Thu Jan 14 09:34:31 2010 NARUSE, Yui <naruse@ruby-lang.org> + + * string.c (rb_str_concat): raise RangeError when the argument is + negative value. [ruby-core:27583] + Thu Jan 14 08:49:59 2010 Tanaka Akira <akr@fsij.org> * time.c (time_to_r): convert to rational if internal representation @@ -1983,7 +1983,18 @@ rb_str_append(VALUE str, VALUE str2) VALUE rb_str_concat(VALUE str1, VALUE str2) { - if (FIXNUM_P(str2) || TYPE(str2) == T_BIGNUM) { + if (FIXNUM_P(str2)) { + if (NEGFIXABLE(str2)) + rb_raise(rb_eRangeError, "negative argument"); + } + else if (TYPE(str2) == T_BIGNUM) { + if (!RBIGNUM_SIGN(str2)) + rb_raise(rb_eRangeError, "negative argument"); + } + else { + return rb_str_append(str1, str2); + } + { rb_encoding *enc = STR_ENC_GET(str1); unsigned int c = NUM2UINT(str2); long pos = RSTRING_LEN(str1); @@ -1995,7 +2006,6 @@ rb_str_concat(VALUE str1, VALUE str2) ENC_CODERANGE_SET(str1, cr); return str1; } - return rb_str_append(str1, str2); } st_index_t |