summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorcubicdaiya <[email protected]>2014-03-04 21:58:47 +0900
committercubicdaiya <[email protected]>2014-03-04 21:58:47 +0900
commitebe4711df82e70f5ac1be5921a5654f33746e185 (patch)
tree7d434e820727520da742a1e1854ae7c2dc742378 /src/string.c
parent7a607112c6083634821a6a09b35f72f87272cd99 (diff)
downloadmruby-ebe4711df82e70f5ac1be5921a5654f33746e185.tar.gz
mruby-ebe4711df82e70f5ac1be5921a5654f33746e185.zip
fix off-by-one error in String#rindex(fixnum)
null-terminated string should not be included in search targets.
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/string.c b/src/string.c
index b7f45aef0..ad3ef2c70 100644
--- a/src/string.c
+++ b/src/string.c
@@ -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();