This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
re_intuit_string: fix to work with empty pattern
authorKarl Williamson <khw@cpan.org>
Mon, 24 Feb 2020 20:50:12 +0000 (13:50 -0700)
committerKarl Williamson <khw@cpan.org>
Thu, 27 Feb 2020 18:01:30 +0000 (11:01 -0700)
This would fail should it ever be called with a pattern that only
matched nothing.

regcomp.c

index 0a73f3e..65a8598 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -21338,6 +21338,9 @@ Perl_regprop(pTHX_ const regexp *prog, SV *sv, const regnode *o, const regmatch_
 SV *
 Perl_re_intuit_string(pTHX_ REGEXP * const r)
 {                              /* Assume that RE_INTUIT is set */
+    /* Returns an SV containing a string that must appear in the target for it
+     * to match */
+
     struct regexp *const prog = ReANY(r);
     GET_RE_DEBUG_FLAGS_DECL;
 
@@ -21346,11 +21349,12 @@ Perl_re_intuit_string(pTHX_ REGEXP * const r)
 
     DEBUG_COMPILE_r(
        {
-           const char * const s = SvPV_nolen_const(RX_UTF8(r)
+            if (prog->maxlen > 0) {
+                const char * const s = SvPV_nolen_const(RX_UTF8(r)
                      ? prog->check_utf8 : prog->check_substr);
 
-           if (!PL_colorset) reginitcolors();
-            Perl_re_printf( aTHX_
+                if (!PL_colorset) reginitcolors();
+                Perl_re_printf( aTHX_
                      "%sUsing REx %ssubstr:%s \"%s%.60s%s%s\"\n",
                      PL_colors[4],
                      RX_UTF8(r) ? "utf8 " : "",
@@ -21358,6 +21362,7 @@ Perl_re_intuit_string(pTHX_ REGEXP * const r)
                      s,
                      PL_colors[1],
                      (strlen(s) > PL_dump_re_max_len ? "..." : ""));
+            }
        } );
 
     /* use UTF8 check substring if regexp pattern itself is in UTF8 */