diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-18 13:18:12 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-29 11:05:41 +0900 |
commit | 841eea4bcbfe22d6d1a71381cd1e98ca6b6cfde7 (patch) | |
tree | 8f0b0ca79aaa6be03310c35577246cc0ae642f7f /string.c | |
parent | 0358846f8cb32b3b4e724685b1d72b16fbc8596c (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 6 |
1 files changed, 1 insertions, 5 deletions
@@ -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; } |