Merge pull request #3649 from ksss/sprintf

Fix segmentation fault ref: #3648
This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-05-09 07:40:08 +09:00
committed by GitHub
2 changed files with 14 additions and 8 deletions
+10 -8
View File
@@ -982,15 +982,17 @@ retry:
}
if (dots) PUSH("..", 2);
if (v < 0) {
char c = sign_bits(base, p);
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);
}
}
else if ((flags & (FMINUS|FPREC)) != FMINUS) {
char c = '0';
FILL(c, prec - len);
}
PUSH(s, len);
if (width > 0) {
FILL(' ', width);
+4
View File
@@ -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
"%?" % ""