Fix segmentation fault ref:
MODIFY
mrbgems/mruby-sprintf/src/sprintf.c
mrbgems/mruby-sprintf/src/sprintf.c
@@ -982,6 +982,8 @@ retry:
}
if (dots) PUSH("..", 2);
+ if (prec > len) {
+ CHECK(prec - len);
if (v < 0) {
char c = sign_bits(base, p);
FILL(c, prec - len);
@@ -990,7 +992,7 @@ retry:
char c = '0';
FILL(c, prec - len);
}
-
+ }
PUSH(s, len);
if (width > 0) {
FILL(' ', width);

MODIFY
mrbgems/mruby-sprintf/test/sprintf.rb
mrbgems/mruby-sprintf/test/sprintf.rb
@@ -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
"%?" % ""

Fix segmentation fault ref: #3648