summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/iconv/iconv.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 4736cb1008..4674aa330e 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -755,7 +755,12 @@ iconv_iconv
if (!NIL_P(str)) slen = RSTRING_LEN(StringValue(str));
if (argc != 2 || !RTEST(rb_range_beg_len(n1, &start, &length, slen, 0))) {
if (NIL_P(n1) || ((start = NUM2LONG(n1)) < 0 ? (start += slen) >= 0 : start < slen)) {
- if (!NIL_P(n2)) length = NUM2LONG(n2);
+ if (NIL_P(n2)) {
+ length = -1;
+ }
+ else if ((length = NUM2LONG(n2)) >= slen - start) {
+ length = slen - start;
+ }
}
}