summaryrefslogtreecommitdiff
path: root/ext/stringio/stringio.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r--ext/stringio/stringio.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index fb2eddaa7e..1e464bc9d1 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -767,13 +767,15 @@ strio_ungetc(VALUE self, VALUE c)
check_modifiable(ptr);
if (NIL_P(c)) return Qnil;
- if (FIXNUM_P(c)) {
- int cc = FIX2INT(c);
+ if (RB_INTEGER_TYPE_P(c)) {
+ int len, cc = NUM2INT(c);
char buf[16];
enc = rb_enc_get(ptr->string);
+ len = rb_enc_codelen(cc, enc);
+ if (len <= 0) rb_enc_uint_chr(cc, enc);
rb_enc_mbcput(cc, buf, enc);
- return strio_unget_bytes(ptr, buf, rb_enc_codelen(cc, enc));
+ return strio_unget_bytes(ptr, buf, len);
}
else {
SafeStringValue(c);