aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-07 09:13:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-07 09:13:41 +0000
commit11f74964bc72c235b01fd0018083d41b8c988339 (patch)
treef275f03d35b08e67be82c7c18a3ba9d8d2d09466 /string.c
parent7017320f8bac809918117ffd4cf4f76e19fcf06c (diff)
downloadruby-11f74964bc72c235b01fd0018083d41b8c988339.tar.gz
string.c: negation of LONG_MIN
* string.c (rb_str_update): do not use negation of LONG_MIN, which is negative too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/string.c b/string.c
index 43b8b4e007..be74fd8b72 100644
--- a/string.c
+++ b/string.c
@@ -4435,12 +4435,14 @@ rb_str_update(VALUE str, long beg, long len, VALUE val)
rb_raise(rb_eIndexError, "index %ld out of string", beg);
}
if (beg < 0) {
- if (-beg > slen) {
+ if (beg + slen < 0) {
goto out_of_range;
}
beg += slen;
}
- if (slen < len || slen < beg + len) {
+ assert(beg >= 0);
+ assert(beg <= slen);
+ if (len > slen - beg) {
len = slen - beg;
}
str_modify_keep_cr(str);