aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-18 13:18:12 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit841eea4bcbfe22d6d1a71381cd1e98ca6b6cfde7 (patch)
tree8f0b0ca79aaa6be03310c35577246cc0ae642f7f /string.c
parent0358846f8cb32b3b4e724685b1d72b16fbc8596c (diff)
downloadruby-841eea4bcbfe22d6d1a71381cd1e98ca6b6cfde7.tar.gz
rb_str_subpat_set: 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.
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 1dfbd6503d..f4bcfba6d0 100644
--- a/string.c
+++ b/string.c
@@ -4772,14 +4772,10 @@ rb_str_subpat_set(VALUE str, VALUE re, VALUE backref, VALUE val)
match = rb_backref_get();
nth = rb_reg_backref_number(match, backref);
regs = RMATCH_REGS(match);
- if (nth >= regs->num_regs) {
- out_of_range:
+ if ((nth >= regs->num_regs) || ((nth < 0) && (-nth >= regs->num_regs))) {
rb_raise(rb_eIndexError, "index %d out of regexp", nth);
}
if (nth < 0) {
- if (-nth >= regs->num_regs) {
- goto out_of_range;
- }
nth += regs->num_regs;
}