summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--string.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/string.c b/string.c
index b7ae7069f6..75db0d22e8 100644
--- a/string.c
+++ b/string.c
@@ -8026,7 +8026,8 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, VALUE ary)
if (rsnewline) {
pend = chomp_newline(subptr, pend, enc);
}
- else if (memcmp(pend - rslen, rsptr, rslen) == 0) {
+ else if (pend - subptr >= rslen &&
+ memcmp(pend - rslen, rsptr, rslen) == 0) {
pend -= rslen;
}
}