Permalink
Browse files

Better error message

Raise argument error with the better message, at the only place
where the size to fill can be negative.
  • Loading branch information...
nobu committed Apr 29, 2017
1 parent e05c307 commit ef6e14ee2b1037ed3e8c08bc215d82cd22816ba3
Showing with 4 additions and 1 deletion.
  1. +4 −1 mrbgems/mruby-sprintf/src/sprintf.c
@@ -116,7 +116,6 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
#define CHECK(l) do {\
/* int cr = ENC_CODERANGE(result);*/\
if ((l) < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "illegal specifier"); \
while ((l) >= bsiz - blen) {\
bsiz*=2;\
if (bsiz < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "too big specifier"); \
@@ -1059,6 +1058,10 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
if ((flags&FWIDTH) && need < width)
need = width;
need += 20;
if (need <= 0) {
mrb_raise(mrb, E_ARGUMENT_ERROR,
(width > prec ? "width too big" : "prec too big"));
}
CHECK(need);
n = snprintf(&buf[blen], need, fbuf, fval);

0 comments on commit ef6e14e

Please sign in to comment.