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: ...@@ -982,15 +982,17 @@ retry:
} }
if (dots) PUSH("..", 2); if (dots) PUSH("..", 2);
if (v < 0) { if (prec > len) {
char c = sign_bits(base, p); CHECK(prec - len);
FILL(c, prec - len); if (v < 0) {
} char c = sign_bits(base, p);
else if ((flags & (FMINUS|FPREC)) != FMINUS) { FILL(c, prec - len);
char c = '0'; }
FILL(c, prec - len); else if ((flags & (FMINUS|FPREC)) != FMINUS) {
char c = '0';
FILL(c, prec - len);
}
} }
PUSH(s, len); PUSH(s, len);
if (width > 0) { if (width > 0) {
FILL(' ', width); FILL(' ', width);
......
...@@ -87,6 +87,10 @@ assert("String#% with invalid chr") do ...@@ -87,6 +87,10 @@ assert("String#% with invalid chr") do
end end
end end
assert("String#% %b") do
assert_equal("..10115", "%0b5" % -5)
end
assert("String#% invalid format") do assert("String#% invalid format") do
assert_raise ArgumentError 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