ruby-changes:14486
From: naruse <ko1@a...>
Date: Thu, 14 Jan 2010 09:39:56 +0900 (JST)
Subject: [ruby-changes:14486] Ruby:r26323 (trunk): * string.c (rb_str_concat): raise RangeError when the argument is
naruse 2010-01-14 09:39:40 +0900 (Thu, 14 Jan 2010) New Revision: 26323 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26323 Log: * string.c (rb_str_concat): raise RangeError when the argument is negative value. [ruby-core:27583] Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 26322) +++ ChangeLog (revision 26323) @@ -1,3 +1,8 @@ +Thu Jan 14 09:34:31 2010 NARUSE, Yui <naruse@r...> + + * 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@f...> * time.c (time_to_r): convert to rational if internal representation Index: string.c =================================================================== --- string.c (revision 26322) +++ string.c (revision 26323) @@ -1983,7 +1983,18 @@ 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 @@ ENC_CODERANGE_SET(str1, cr); return str1; } - return rb_str_append(str1, str2); } st_index_t -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/