summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-20 07:32:23 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-20 07:32:23 +0000
commitdc2d359b70725e890eff902e25bc0176245b0784 (patch)
treecbb9d2aa5821461076f39ee31a6b224297ae05b4 /re.c
parent44ba4fd36248d8d496cb31cf2f33a0ad0c19b5a2 (diff)
re.c: consider the case of RMatch::regexp is nil
Follow r49675, r57098 and r57110. Don't assume RMatch::regexp always contains a valid Regexp instance; it will be Qnil if the MatchData is created by rb_backref_set_string(). [ruby-core:78741] [Bug #13054] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/re.c b/re.c
index 87df1a6ef0..f8682e23e1 100644
--- a/re.c
+++ b/re.c
@@ -1089,6 +1089,8 @@ static VALUE
match_names(VALUE match)
{
match_check(match);
+ if (NIL_P(RMATCH(match)->regexp))
+ return rb_ary_new_capa(0);
return rb_reg_names(RMATCH(match)->regexp);
}
@@ -2078,6 +2080,8 @@ match_named_captures(VALUE match)
struct MEMO *memo;
match_check(match);
+ if (NIL_P(RMATCH(match)->regexp))
+ return rb_hash_new();
hash = rb_hash_new();
memo = MEMO_NEW(hash, match, 0);
@@ -2948,7 +2952,7 @@ match_hash(VALUE match)
match_check(match);
hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str));
- hashval = rb_hash_uint(hashval, reg_hash(RMATCH(match)->regexp));
+ hashval = rb_hash_uint(hashval, reg_hash(match_regexp(match)));
regs = RMATCH_REGS(match);
hashval = rb_hash_uint(hashval, regs->num_regs);
hashval = rb_hash_uint(hashval, rb_memhash(regs->beg, regs->num_regs * sizeof(*regs->beg)));
@@ -2970,11 +2974,12 @@ static VALUE
match_equal(VALUE match1, VALUE match2)
{
const struct re_registers *regs1, *regs2;
+
if (match1 == match2) return Qtrue;
if (!RB_TYPE_P(match2, T_MATCH)) return Qfalse;
if (!RMATCH(match1)->regexp || !RMATCH(match2)->regexp) return Qfalse;
if (!rb_str_equal(RMATCH(match1)->str, RMATCH(match2)->str)) return Qfalse;
- if (!rb_reg_equal(RMATCH(match1)->regexp, RMATCH(match2)->regexp)) return Qfalse;
+ if (!rb_reg_equal(match_regexp(match1), match_regexp(match2))) return Qfalse;
regs1 = RMATCH_REGS(match1);
regs2 = RMATCH_REGS(match2);
if (regs1->num_regs != regs2->num_regs) return Qfalse;