[前][次][番号順一覧][スレッド一覧]

ruby-changes:45727

From: nobu <ko1@a...>
Date: Tue, 7 Mar 2017 18:13:46 +0900 (JST)
Subject: [ruby-changes:45727] nobu:r57800 (trunk): string.c: negation of LONG_MIN

nobu	2017-03-07 18:13:41 +0900 (Tue, 07 Mar 2017)

  New Revision: 57800

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57800

  Log:
    string.c: negation of LONG_MIN
    
    * string.c (rb_str_update): do not use negation of LONG_MIN, which
      is negative too.

  Modified files:
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: string.c
===================================================================
--- string.c	(revision 57799)
+++ string.c	(revision 57800)
@@ -4435,12 +4435,14 @@ rb_str_update(VALUE str, long beg, long https://github.com/ruby/ruby/blob/trunk/string.c#L4435
 	rb_raise(rb_eIndexError, "index %ld out of string", beg);
     }
     if (beg < 0) {
-	if (-beg > slen) {
+	if (beg + slen < 0) {
 	    goto out_of_range;
 	}
 	beg += slen;
     }
-    if (slen < len || slen < beg + len) {
+    assert(beg >= 0);
+    assert(beg <= slen);
+    if (len > slen - beg) {
 	len = slen - beg;
     }
     str_modify_keep_cr(str);
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 57799)
+++ test/ruby/test_string.rb	(revision 57800)
@@ -202,6 +202,8 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L202
     assert_equal("fobar", s)
 
     assert_raise(ArgumentError) { "foo"[1, 2, 3] = "" }
+
+    assert_raise(IndexError) {"foo"[RbConfig::Limits["LONG_MIN"]] = "l"}
   end
 
   def test_CMP # '<=>'

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]