ruby-changes:30223
From: glass <ko1@a...>
Date: Wed, 31 Jul 2013 20:18:29 +0900 (JST)
Subject: [ruby-changes:30223] glass:r42275 (trunk): * string.c (rb_str_rindex): fix bug introduced in r42269.
glass 2013-07-31 20:18:18 +0900 (Wed, 31 Jul 2013) New Revision: 42275 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42275 Log: * string.c (rb_str_rindex): fix bug introduced in r42269. "".rindex("") should return 0. (str_rindex): ditto. Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42274) +++ ChangeLog (revision 42275) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 31 20:11:01 2013 Masaki Matsushita <glass.saga@g...> + + * 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 <akr@f...> * bignum.c (MAX_BIG2STR_TABLE_ENTRIES): Use SIZEOF_SIZE_T. Index: string.c =================================================================== --- string.c (revision 42274) +++ string.c (revision 42275) @@ -2667,19 +2667,20 @@ rb_str_index_m(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L2667 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 c https://github.com/ruby/ruby/blob/trunk/string.c#L2702 } #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 https://github.com/ruby/ruby/blob/trunk/string.c#L2754 } 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/