summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-11-08 15:06:15 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-11-08 16:13:30 +0900
commit001606097b3239b84a5910e2f2bc814074cb6973 (patch)
treeb7234edf5c0453e2715f82a00746d5415f1619d0 /re.c
parent4a7d6c2852aa734506be83c932168e8f974687b5 (diff)
downloadruby-001606097b3239b84a5910e2f2bc814074cb6973.tar.gz
Suppress false warning by a bug of gcc
GCC [Bug 99578] seems triggered by calling `rb_reg_last_match` before `match_check(match)`, probably by `NIL_P(match)` in `rb_reg_nth_match`. [Bug 99578]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
Diffstat (limited to 're.c')
-rw-r--r--re.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/re.c b/re.c
index c65e4a58eb..1b83148321 100644
--- a/re.c
+++ b/re.c
@@ -1066,12 +1066,13 @@ update_char_offset(VALUE match)
}
}
-static void
+static VALUE
match_check(VALUE match)
{
if (!RMATCH(match)->regexp) {
rb_raise(rb_eTypeError, "uninitialized MatchData");
}
+ return match;
}
/* :nodoc: */
@@ -2268,16 +2269,16 @@ match_values_at(int argc, VALUE *argv, VALUE match)
static VALUE
match_to_s(VALUE match)
{
- VALUE str = rb_reg_last_match(match);
+ VALUE str = rb_reg_last_match(match_check(match));
- match_check(match);
if (NIL_P(str)) str = rb_str_new(0,0);
return str;
}
static int
match_named_captures_iter(const OnigUChar *name, const OnigUChar *name_end,
- int back_num, int *back_refs, OnigRegex regex, void *arg) {
+ int back_num, int *back_refs, OnigRegex regex, void *arg)
+{
struct MEMO *memo = MEMO_CAST(arg);
VALUE hash = memo->v1;
VALUE match = memo->v2;