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
This commit is contained in:
parent
f7fb4e00f7
commit
77e9edc334
@ -1,3 +1,9 @@
|
|||||||
|
Thu Dec 3 15:33:08 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]
|
||||||
|
|
||||||
Thu Dec 3 14:22:16 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Dec 3 14:22:16 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* range.c (range_to_s): should be infected by the receiver.
|
* range.c (range_to_s): should be infected by the receiver.
|
||||||
|
19
sprintf.c
19
sprintf.c
@ -1107,16 +1107,19 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
|||||||
done += prec;
|
done += prec;
|
||||||
}
|
}
|
||||||
if ((flags & FWIDTH) && width > done) {
|
if ((flags & FWIDTH) && width > done) {
|
||||||
|
int fill = ' ';
|
||||||
|
long shifting = 0;
|
||||||
if (!(flags&FMINUS)) {
|
if (!(flags&FMINUS)) {
|
||||||
long i, shifting = (flags&FZERO) ? done - prefix : done;
|
shifting = done;
|
||||||
for (i = 1; i <= shifting; i++)
|
if (flags&FZERO) {
|
||||||
buf[width - i] = buf[done - i];
|
shifting -= prefix;
|
||||||
blen -= shifting;
|
fill = '0';
|
||||||
FILL((flags&FZERO) ? '0' : ' ', width - done);
|
|
||||||
blen += shifting;
|
|
||||||
} else {
|
|
||||||
FILL(' ', width - done);
|
|
||||||
}
|
}
|
||||||
|
blen -= shifting;
|
||||||
|
memmove(&buf[blen + width - done], &buf[blen], shifting);
|
||||||
|
}
|
||||||
|
FILL(fill, width - done);
|
||||||
|
blen += shifting;
|
||||||
}
|
}
|
||||||
RB_GC_GUARD(val);
|
RB_GC_GUARD(val);
|
||||||
break;
|
break;
|
||||||
|
@ -166,6 +166,9 @@ class TestSprintf < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
bug11766 = '[ruby-core:71806] [Bug #11766]'
|
||||||
|
assert_equal("x"*10+" 1.0", sprintf("x"*10+"%8.1f", 1r))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_hash
|
def test_hash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user