diff options
Diffstat (limited to 'sprintf.c')
| -rw-r--r-- | sprintf.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -67,7 +67,8 @@ sign_bits(int base, const char *p) #define CHECK(l) do {\ int cr = ENC_CODERANGE(result);\ - while ((l) >= bsiz - blen) {\ + RUBY_ASSERT(bsiz >= blen); \ + while ((l) > bsiz - blen) {\ bsiz*=2;\ if (bsiz<0) rb_raise(rb_eArgError, "too big specifier");\ }\ @@ -247,8 +248,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } #define update_coderange(partial) do { \ - if (coderange != ENC_CODERANGE_BROKEN && scanned < blen \ - && rb_enc_to_index(enc) /* != ENCINDEX_ASCII_8BIT */) { \ + if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) { \ int cr = coderange; \ scanned += rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &cr); \ ENC_CODERANGE_SET(result, \ @@ -440,8 +440,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) { VALUE val = GETARG(); VALUE tmp; - unsigned int c; - int n; + unsigned int c = 0; + int n, encidx = 0; tmp = rb_check_string_type(val); if (!NIL_P(tmp)) { @@ -451,11 +451,13 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) goto format_s1; } n = NUM2INT(val); - if (n >= 0) n = rb_enc_codelen((c = n), enc); + if (n >= 0) { + n = rb_enc_codelen((c = n), enc); + encidx = rb_ascii8bit_appendable_encoding_index(enc, c); + } if (n <= 0) { rb_raise(rb_eArgError, "invalid character"); } - int encidx = rb_ascii8bit_appendable_encoding_index(enc, c); if (encidx >= 0 && encidx != rb_enc_to_index(enc)) { /* special case */ rb_enc_associate_index(result, encidx); @@ -808,7 +810,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) if (FIXNUM_P(num)) { if ((SIGNED_VALUE)num < 0) { long n = -FIX2LONG(num); - num = LONG2FIX(n); + num = LONG2NUM(n); sign = -1; } } |
