This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix scanning for code blocks
authorDavid Mitchell <davem@iabyn.com>
Wed, 7 Dec 2011 11:26:14 +0000 (11:26 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 13 Jun 2012 12:32:46 +0000 (13:32 +0100)
The toke code that scanned a pattern string to see if it looked like it
had any code blocks in it, used the wrong pointers. This then failed if
the pattern spread over multiple lines and buffers got reassigned.

toke.c

diff --git a/toke.c b/toke.c
index d42f653..0570a15 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9190,8 +9190,10 @@ S_scan_pat(pTHX_ char *start, I32 type)
      * anon CV. False positives like qr/[(?{]/ are harmless */
 
     if (type == OP_QR) {
-       char *p;
-       for (p = start; p < s; p++) {
+       STRLEN len;
+       char *e, *p = SvPV(PL_lex_stuff, len);
+       e = p + len;
+       for (; p < e; p++) {
            if (p[0] == '(' && p[1] == '?'
                && (p[2] == '{' || (p[2] == '?' && p[3] == '{')))
            {
@@ -9199,6 +9201,7 @@ S_scan_pat(pTHX_ char *start, I32 type)
                break;
            }
        }
+       pm->op_pmflags |= PMf_IS_QR;
     }
 
     while (*s && S_pmflag(aTHX_ valid_flags, &(pm->op_pmflags), &s, &charset)) {};