diff options
Diffstat (limited to 'sprintf.c')
-rw-r--r-- | sprintf.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -394,7 +394,15 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) VALUE val = GETARG(); char c; - c = NUM2INT(val) & 0xff; + if (rb_check_string_type(val)) { + if (RSTRING(val)->len != 1) { + rb_raise(rb_eArgError, "%%c requires a character"); + } + c = RSTRING(val)->ptr[0]; + } + else { + c = NUM2INT(val) & 0xff; + } if (!(flags & FWIDTH)) { PUSH(&c, 1); } |