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

ruby-changes:40795

From: nagachika <ko1@a...>
Date: Fri, 4 Dec 2015 04:55:45 +0900 (JST)
Subject: [ruby-changes:40795] nagachika:r52874 (ruby_2_2): merge revision(s) 52869: [Backport #11766]

nagachika	2015-12-04 04:55:23 +0900 (Fri, 04 Dec 2015)

  New Revision: 52874

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

  Log:
    merge revision(s) 52869: [Backport #11766]
    
    * sprintf.c (rb_str_format): fix wrong shifting position in
      Rational conversion when not at the beginning of the result.
      [ruby-core:71806] [Bug #11766]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/sprintf.c
    branches/ruby_2_2/test/ruby/test_sprintf.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 52873)
+++ ruby_2_2/ChangeLog	(revision 52874)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Fri Dec  4 04:46:33 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* sprintf.c (rb_str_format): fix wrong shifting position in
+	  Rational conversion when not at the beginning of the result.
+	  [ruby-core:71806] [Bug #11766]
+
 Fri Dec  4 02:42:37 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* range.c (range_to_s): should be infected by the receiver.
Index: ruby_2_2/sprintf.c
===================================================================
--- ruby_2_2/sprintf.c	(revision 52873)
+++ ruby_2_2/sprintf.c	(revision 52874)
@@ -1095,16 +1095,19 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/ruby_2_2/sprintf.c#L1095
 		    done += prec;
 		}
 		if ((flags & FWIDTH) && width > done) {
+		    int fill = ' ';
+		    long shifting = 0;
 		    if (!(flags&FMINUS)) {
-			long i, shifting = (flags&FZERO) ? done - prefix : done;
-			for (i = 1; i <= shifting; i++)
-			    buf[width - i] = buf[done - i];
+			shifting = done;
+			if (flags&FZERO) {
+			    shifting -= prefix;
+			    fill = '0';
+			}
 			blen -= shifting;
-			FILL((flags&FZERO) ? '0' : ' ', width - done);
-			blen += shifting;
-		    } else {
-			FILL(' ', width - done);
+			memmove(&buf[blen + width - done], &buf[blen], shifting);
 		    }
+		    FILL(fill, width - done);
+		    blen += shifting;
 		}
 		RB_GC_GUARD(val);
 		break;
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 52873)
+++ ruby_2_2/version.h	(revision 52874)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.4"
 #define RUBY_RELEASE_DATE "2015-12-04"
-#define RUBY_PATCHLEVEL 219
+#define RUBY_PATCHLEVEL 220
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 12
Index: ruby_2_2/test/ruby/test_sprintf.rb
===================================================================
--- ruby_2_2/test/ruby/test_sprintf.rb	(revision 52873)
+++ ruby_2_2/test/ruby/test_sprintf.rb	(revision 52874)
@@ -166,6 +166,9 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_sprintf.rb#L166
         end
       end
     end
+
+    bug11766 = '[ruby-core:71806] [Bug #11766]'
+    assert_equal("x"*10+"     1.0", sprintf("x"*10+"%8.1f", 1r))
   end
 
   def test_hash

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r52869


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

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