ruby-changes:67953
From: Nobuyoshi <ko1@a...>
Date: Sun, 12 Sep 2021 11:17:02 +0900 (JST)
Subject: [ruby-changes:67953] c5570a7c11 (master): Extract backref_number_check
https://git.ruby-lang.org/ruby.git/commit/?id=c5570a7c11 From c5570a7c11ba0872e171500a548f2ecb82e94588 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 11 Sep 2021 22:50:59 +0900 Subject: Extract backref_number_check --- re.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/re.c b/re.c index 4840ce0..2afa824 100644 --- a/re.c +++ b/re.c @@ -1159,6 +1159,13 @@ name_to_backref_error(VALUE name) https://github.com/ruby/ruby/blob/trunk/re.c#L1159 name); } +static void +backref_number_check(struct re_registers *regs, int i) +{ + if (i < 0 || regs->num_regs <= i) + rb_raise(rb_eIndexError, "index %d out of matches", i); +} + static int match_backref_number(VALUE match, VALUE backref) { @@ -1217,8 +1224,7 @@ match_offset(VALUE match, VALUE n) https://github.com/ruby/ruby/blob/trunk/re.c#L1224 struct re_registers *regs = RMATCH_REGS(match); match_check(match); - if (i < 0 || regs->num_regs <= i) - rb_raise(rb_eIndexError, "index %d out of matches", i); + backref_number_check(regs, i); if (BEG(i) < 0) return rb_assoc_new(Qnil, Qnil); @@ -1253,8 +1259,7 @@ match_begin(VALUE match, VALUE n) https://github.com/ruby/ruby/blob/trunk/re.c#L1259 struct re_registers *regs = RMATCH_REGS(match); match_check(match); - if (i < 0 || regs->num_regs <= i) - rb_raise(rb_eIndexError, "index %d out of matches", i); + backref_number_check(regs, i); if (BEG(i) < 0) return Qnil; @@ -1288,8 +1293,7 @@ match_end(VALUE match, VALUE n) https://github.com/ruby/ruby/blob/trunk/re.c#L1293 struct re_registers *regs = RMATCH_REGS(match); match_check(match); - if (i < 0 || regs->num_regs <= i) - rb_raise(rb_eIndexError, "index %d out of matches", i); + backref_number_check(regs, i); if (BEG(i) < 0) return Qnil; -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/