aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/sprintf.c b/sprintf.c
index 580a54ae8f..22c8c12d1c 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -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);
}