summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/string.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/string.c b/src/string.c
index a0d75f544..9efc89b34 100644
--- a/src/string.c
+++ b/src/string.c
@@ -469,7 +469,7 @@ str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
beg += clen;
if (beg < 0) return mrb_nil_value();
}
- if (beg + len > clen)
+ if (len > clen - beg)
len = clen - beg;
if (len <= 0) {
len = 0;