summaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/string.c b/string.c
index 473eccef7..52c3a70b5 100644
--- a/string.c
+++ b/string.c
@@ -1010,8 +1010,13 @@ rb_str_rindex_m(argc, argv, str)
char *p = RSTRING(str)->ptr + pos;
char *pbeg = RSTRING(str)->ptr;
- while (pbeg <= --p) {
+ if (pos == RSTRING(str)->len) {
+ if (pos == 0) return Qnil;
+ --p;
+ }
+ while (pbeg <= p) {
if (*p == c) return LONG2NUM(p - RSTRING(str)->ptr);
+ p--;
}
return Qnil;
}