summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-18 10:29:25 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit0358846f8cb32b3b4e724685b1d72b16fbc8596c (patch)
tree69e2c107a467099aa320a67a87e6ff1082554555 /string.c
parentd49924ed81af7f5f00841ce7b4aa423a924d3af0 (diff)
rb_str_update: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'string.c')
-rw-r--r--string.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/string.c b/string.c
index 8ccfac5a77..1dfbd6503d 100644
--- a/string.c
+++ b/string.c
@@ -4729,14 +4729,10 @@ rb_str_update(VALUE str, long beg, long len, VALUE val)
enc = rb_enc_check(str, val);
slen = str_strlen(str, enc); /* rb_enc_check */
- if (slen < beg) {
- out_of_range:
+ if ((slen < beg) || ((beg < 0) && (beg + slen < 0))) {
rb_raise(rb_eIndexError, "index %ld out of string", beg);
}
if (beg < 0) {
- if (beg + slen < 0) {
- goto out_of_range;
- }
beg += slen;
}
assert(beg >= 0);