summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-03 19:55:23 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-03 19:55:23 +0000
commitf50d0b98bd37840bb00292b437afff888d89ad05 (patch)
tree8a67d433d262fb59193e568c389e8a3e871b5345
parentc35409c2762585a40b2b71ab459ba315359fb955 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@52874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--sprintf.c17
-rw-r--r--test/ruby/test_sprintf.rb3
-rw-r--r--version.h2
4 files changed, 20 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 12e2a00b9a..34258500f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Dec 4 04:46:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* range.c (range_to_s): should be infected by the receiver.
diff --git a/sprintf.c b/sprintf.c
index d91d850c9d..355b4adf00 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1095,16 +1095,19 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
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;
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index 15c809c695..cfac7efa92 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -166,6 +166,9 @@ class TestSprintf < Test::Unit::TestCase
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
diff --git a/version.h b/version.h
index 90b28245a0..4e798cc525 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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