diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-03 19:55:23 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-03 19:55:23 +0000 |
commit | f50d0b98bd37840bb00292b437afff888d89ad05 (patch) | |
tree | 8a67d433d262fb59193e568c389e8a3e871b5345 /sprintf.c | |
parent | c35409c2762585a40b2b71ab459ba315359fb955 (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
Diffstat (limited to 'sprintf.c')
-rw-r--r-- | sprintf.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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; |