summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-03 06:33:13 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-03 06:33:13 (GMT)
commit77e9edc3348f33904424ceaa14e9692b8b91d7f3 (patch)
tree4cc7a6af54afd5f8a38a1bdead524f160dd69e8b /sprintf.c
parentf7fb4e00f721a9d0520b0bbeab687d122f6759ff (diff)
sprintf.c: fix garbage inserted with Rational
* 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/trunk@52869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/sprintf.c b/sprintf.c
index 99c97a0..84d5fd1 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1107,16 +1107,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;