fix off-by-one error in String#rindex(fixnum)

null-terminated string should not be included in search targets.
This commit is contained in:
cubicdaiya
2014-03-04 21:58:47 +09:00
parent 7a607112c6
commit ebe4711df8
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -1660,7 +1660,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str)
mrb_int len = RSTRING_LEN(str);
unsigned char *p = (unsigned char*)RSTRING_PTR(str);
for (pos=len;pos>=0;pos--) {
for (pos=len-1;pos>=0;pos--) {
if (p[pos] == c) return mrb_fixnum_value(pos);
}
return mrb_nil_value();