From 5fb4f81eecc03b418067f6e8bf24e97b774eb968 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 26 Jan 2015 02:00:43 +0000 Subject: cstr.c: get rid of exception * ext/-test-/string/cstr.c (bug_str_cstr_term_char): get rid of invalid byte sequence exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/-test-/string/cstr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ext/-test-/string') diff --git a/ext/-test-/string/cstr.c b/ext/-test-/string/cstr.c index 7759cbdcf0..50214bb008 100644 --- a/ext/-test-/string/cstr.c +++ b/ext/-test-/string/cstr.c @@ -28,7 +28,15 @@ bug_str_cstr_term_char(VALUE str) rb_encoding *enc = rb_enc_get(str); RSTRING_GETMEM(str, s, len); - c = rb_enc_codepoint(&s[len], &s[len+rb_enc_mbminlen(enc)], enc); + s += len; + len = rb_enc_mbminlen(enc); + c = rb_enc_precise_mbclen(s, s + len, enc); + if (!MBCLEN_CHARFOUND_P(c)) { + c = (unsigned char)*s; + } + else { + c = rb_enc_mbc_to_codepoint(s, s + len, enc); + } return c ? rb_enc_uint_chr((unsigned int)c, enc) : Qnil; } -- cgit v1.2.3