Commit 011e0bb0 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #3649 from ksss/sprintf

Fix segmentation fault ref: #3648
parents ef305305 30df7c87
......@@ -982,15 +982,17 @@ retry:
}
if (dots) PUSH("..", 2);
if (v < 0) {
char c = sign_bits(base, p);
FILL(c, prec - len);
}
else if ((flags & (FMINUS|FPREC)) != FMINUS) {
char c = '0';
FILL(c, prec - len);
if (prec > len) {
CHECK(prec - len);
if (v < 0) {
char c = sign_bits(base, p);
FILL(c, prec - len);
}
else if ((flags & (FMINUS|FPREC)) != FMINUS) {
char c = '0';
FILL(c, prec - len);
}
}
PUSH(s, len);
if (width > 0) {
FILL(' ', width);
......
......@@ -87,6 +87,10 @@ assert("String#% with invalid chr") do
end
end
assert("String#% %b") do
assert_equal("..10115", "%0b5" % -5)
end
assert("String#% invalid format") do
assert_raise ArgumentError do
"%?" % ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment