aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/string.c b/string.c
index 4ae149f0c4..c07ddc9438 100644
--- a/string.c
+++ b/string.c
@@ -2488,14 +2488,14 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
e = RSTRING_END(str);
t = RSTRING_PTR(sub);
slen = RSTRING_LEN(sub);
- for (;;) {
- s = str_nth(sbeg, e, pos, enc, singlebyte);
- if (!s) return -1;
+ s = str_nth(sbeg, e, pos, enc, singlebyte);
+ while (s) {
if (memcmp(s, t, slen) == 0) {
return pos;
}
if (pos == 0) break;
pos--;
+ s = rb_enc_prev_char(sbeg, s, e, enc);
}
return -1;
}