aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--string.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/string.c b/string.c
index e239a27a4c..4968e86d74 100644
--- a/string.c
+++ b/string.c
@@ -2386,7 +2386,7 @@ rb_str_subpos(VALUE str, long beg, long *lenp)
beg += blen;
if (beg < 0) return 0;
}
- if (beg + len > blen)
+ if (len > blen - beg)
len = blen - beg;
if (len < 0) return 0;
p = s + beg;