diff --git a/sprintf.c b/sprintf.c index 0438b5e32c..92738783eb 100644 --- a/sprintf.c +++ b/sprintf.c @@ -55,8 +55,9 @@ sign_bits(int base, const char *p) #define CHECK(l) do {\ int cr = ENC_CODERANGE(result);\ - while (blen + (l) >= bsiz) {\ + while ((l) >= bsiz - blen) {\ bsiz*=2;\ + if (bsiz<0) rb_raise(rb_eArgError, "too big specifier");\ }\ rb_str_resize(result, bsiz);\ ENC_CODERANGE_SET(result, cr);\