summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
Diffstat (limited to 're.c')
-rw-r--r--re.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/re.c b/re.c
index e51b782cf6..ef49281454 100644
--- a/re.c
+++ b/re.c
@@ -1581,7 +1581,6 @@ rb_reg_prepare_re(VALUE re, VALUE str)
{
int r;
OnigErrorInfo einfo;
- const char *pattern;
VALUE unescaped;
rb_encoding *fixed_enc = 0;
rb_encoding *enc = rb_reg_prepare_enc(re, str, 1);
@@ -1590,11 +1589,13 @@ rb_reg_prepare_re(VALUE re, VALUE str)
if (reg->enc == enc) return reg;
rb_reg_check(re);
- pattern = RREGEXP_SRC_PTR(re);
+
+ VALUE src_str = RREGEXP_SRC(re);
+ const char *pattern = RSTRING_PTR(src_str);
onig_errmsg_buffer err = "";
unescaped = rb_reg_preprocess(
- pattern, pattern + RREGEXP_SRC_LEN(re), enc,
+ pattern, pattern + RSTRING_LEN(src_str), enc,
&fixed_enc, err, 0);
if (NIL_P(unescaped)) {
@@ -1639,6 +1640,7 @@ rb_reg_prepare_re(VALUE re, VALUE str)
reg->timelimit = timelimit;
RB_GC_GUARD(unescaped);
+ RB_GC_GUARD(src_str);
return reg;
}