summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/string.c b/string.c
index 1f7321a1ce..ed51fa4af7 100644
--- a/string.c
+++ b/string.c
@@ -3993,8 +3993,10 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
}
if (RB_TYPE_P(sub, T_REGEXP)) {
- if (pos > str_strlen(str, NULL))
+ if (pos > str_strlen(str, NULL)) {
+ rb_backref_set(Qnil);
return Qnil;
+ }
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
rb_enc_check(str, sub), single_byte_optimizable(str));