summaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/string.c b/string.c
index 9418bfe2c..493ef5d87 100644
--- a/string.c
+++ b/string.c
@@ -2569,6 +2569,8 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
switch (TYPE(sub)) {
case T_REGEXP:
+ if (pos > str_strlen(str, STR_ENC_GET(str)))
+ return Qnil;
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
rb_enc_check(str, sub), single_byte_optimizable(str));