summaryrefslogtreecommitdiff
path: root/ext/-test-/string/cstr.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-26 02:00:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-26 02:00:43 +0000
commit5fb4f81eecc03b418067f6e8bf24e97b774eb968 (patch)
treee0cc4a95338eee8e533e7d5042227ca6f4d1d747 /ext/-test-/string/cstr.c
parent9f9268479175c6da9caa0e7cccbfa173ffed6f39 (diff)
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
Diffstat (limited to 'ext/-test-/string/cstr.c')
-rw-r--r--ext/-test-/string/cstr.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/ext/-test-/string/cstr.c b/ext/-test-/string/cstr.c
index 7759cbd..50214bb 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;
}