From 0e2d0bb9705c21c4cfecf68a9ccf6c54e040d667 Mon Sep 17 00:00:00 2001 From: glass Date: Wed, 31 Jul 2013 11:18:18 +0000 Subject: * string.c (rb_str_rindex): fix bug introduced in r42269. "".rindex("") should return 0. (str_rindex): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ string.c | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b805774ab..1968180a42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jul 31 20:11:01 2013 Masaki Matsushita + + * string.c (rb_str_rindex): fix bug introduced in r42269. + "".rindex("") should return 0. + (str_rindex): ditto. + Wed Jul 31 19:55:33 2013 Tanaka Akira * bignum.c (MAX_BIG2STR_TABLE_ENTRIES): Use SIZEOF_SIZE_T. diff --git a/string.c b/string.c index 8d3e1fe274..8c016fc8e0 100644 --- a/string.c +++ b/string.c @@ -2667,19 +2667,20 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str) return LONG2NUM(pos); } -#if HAVE_MEMRCHR +#ifdef HAVE_MEMRCHR static long -str_rindex(VALUE str, VALUE sub, const char *s, rb_encoding *enc) +str_rindex(VALUE str, VALUE sub, const char *s, long pos, rb_encoding *enc) { char *hit, *adjusted; int c; long slen, searchlen; char *sbeg, *e, *t; + slen = RSTRING_LEN(sub); + if (slen == 0) return pos; sbeg = RSTRING_PTR(str); e = RSTRING_END(str); t = RSTRING_PTR(sub); - slen = RSTRING_LEN(sub); c = *t & 0xff; searchlen = s - sbeg + 1; @@ -2701,7 +2702,7 @@ str_rindex(VALUE str, VALUE sub, const char *s, rb_encoding *enc) } #else static long -str_rindex(VALUE str, VALUE sub, const char *s, rb_encoding *enc) +str_rindex(VALUE str, VALUE sub, const char *s, long pos, rb_encoding *enc) { long slen; char *sbeg, *e, *t; @@ -2753,7 +2754,7 @@ rb_str_rindex(VALUE str, VALUE sub, long pos) } s = str_nth(sbeg, RSTRING_END(str), pos, enc, singlebyte); - return str_rindex(str, sub, s, enc); + return str_rindex(str, sub, s, pos, enc); } -- cgit v1.2.3