summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-31 11:18:18 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-31 11:18:18 +0000
commit0e2d0bb9705c21c4cfecf68a9ccf6c54e040d667 (patch)
tree0a824b3c7c4ffd6526896c51e8f0ec9629d20cef
parentaba8c29a8b3a2921009eca50bfb08bea03ec4164 (diff)
* 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
-rw-r--r--ChangeLog6
-rw-r--r--string.c11
2 files changed, 12 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b80577..1968180 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jul 31 20:11:01 2013 Masaki Matsushita <glass.saga@gmail.com>
+
+ * 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@fsij.org>
* bignum.c (MAX_BIG2STR_TABLE_ENTRIES): Use SIZEOF_SIZE_T.
diff --git a/string.c b/string.c
index 8d3e1fe..8c016fc 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);
}