summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-22 04:33:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-22 04:33:38 +0000
commitd2d9257cd4b122fc5a7dca40594365d765e52011 (patch)
tree1aa501e455b5b0524d3e72877073d3cf0aca8412 /string.c
parent1a95e46cc6194933cf75a4bf91a0bb6502f177a0 (diff)
string.c: raise at invalid byte sequence
* string.c (rb_str_count): raise at invalid byte sequence argument even if single-byte optimization is effective. [ruby-dev:48442] [Bug #10078] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/string.c b/string.c
index b303b56d89..f0ce9b1109 100644
--- a/string.c
+++ b/string.c
@@ -6075,15 +6075,17 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
for (i=0; i<argc; i++) {
VALUE tstr = argv[i];
- const unsigned char *utstr;
+ const char *ptstr;
StringValue(tstr);
enc = rb_enc_check(str, tstr);
if (argc == 1 && RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
- (utstr = (const OnigUChar *)RSTRING_PTR(tstr), ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, utstr, utstr+1)) &&
+ (ptstr = RSTRING_PTR(tstr),
+ ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, (const unsigned char *)ptstr, (const unsigned char *)ptstr+1)) &&
!is_broken_string(str)) {
int n = 0;
- unsigned char c = utstr[0];
+ int clen;
+ unsigned char c = rb_enc_codepoint_len(ptstr, ptstr+1, &clen, enc);
s = RSTRING_PTR(str);
if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);