diff --git string.c string.c index deeed4a12a..b4db760647 100644 --- string.c +++ string.c @@ -8436,7 +8436,6 @@ rb_str_count(int argc, VALUE *argv, VALUE str) char *s, *send; int i; int ascompat; - size_t n = 0; rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); @@ -8449,6 +8448,7 @@ rb_str_count(int argc, VALUE *argv, VALUE str) (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; int clen; unsigned char c = rb_enc_codepoint_len(ptstr, ptstr+1, &clen, enc); @@ -8458,7 +8458,7 @@ rb_str_count(int argc, VALUE *argv, VALUE str) while (s < send) { if (*(unsigned char*)s++ == c) n++; } - return SIZET2NUM(n); + return INT2NUM(n); } } @@ -8474,12 +8474,13 @@ rb_str_count(int argc, VALUE *argv, VALUE str) if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0); send = RSTRING_END(str); ascompat = rb_enc_asciicompat(enc); + i = 0; while (s < send) { unsigned int c; if (ascompat && (c = *(unsigned char*)s) < 0x80) { if (table[c]) { - n++; + i++; } s++; } @@ -8487,13 +8488,13 @@ rb_str_count(int argc, VALUE *argv, VALUE str) int clen; c = rb_enc_codepoint_len(s, send, &clen, enc); if (tr_find(c, table, del, nodel)) { - n++; + i++; } s += clen; } } - return SIZET2NUM(n); + return INT2NUM(i); } static VALUE