diff options
| -rw-r--r-- | include/mruby/value.h | 2 | ||||
| -rw-r--r-- | src/string.c | 2 | ||||
| -rw-r--r-- | test/t/string.rb | 3 |
3 files changed, 5 insertions, 2 deletions
diff --git a/include/mruby/value.h b/include/mruby/value.h index 562817678..d51fbb7bc 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -509,4 +509,4 @@ mrb_bool_value(mrb_bool boolean) return v; } -#endif /* MRUBY_OBJECT_H */ +#endif /* MRUBY_VALUE_H */ 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(); diff --git a/test/t/string.rb b/test/t/string.rb index 2ebaad1b7..0556d12af 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -330,6 +330,9 @@ assert('String#rindex', '15.2.10.5.31') do assert_nil 'abc'.rindex('d') assert_equal 0, 'abcabc'.rindex('a', 1) assert_equal 3, 'abcabc'.rindex('a', 4) + + assert_equal 3, 'abcabc'.rindex(97) + assert_equal nil, 'abcabc'.rindex(0) end # 'String#scan', '15.2.10.5.32' will be tested in mrbgems. |
