in reply to Worrying regex issue with 5.8.0

This looks to me as though it's the same problem I tripped over: perl -e '$d=qr /\#\#/x; print $d, "\n";' produces:

(?x-ism:\#\#l )
when I thought it ought to produce (?x-ism:\#\#)

I sent it in as a bug report, and it's been fixed:

The memory corruption bug should be corrected by change #17994 :

Change 17994 by rgs@rgs-home on 2002/10/10 20:19:27

        Fix bug #17776 : memory corruption in qr/##/x

The actual bug is due to:

 * So, if /x was used, we scan backwards from the
 * end of the regex. If we find a '#' before we
 * find a newline, we need to add a newline
 * ourself. If we find a '\n' first (or if we
 * don't find '#' or '\n'), we don't need to add
 * anything.  -jfriedl
So if you can reorganise to stop this occuring, you'll be alright.

--
Tommy
Too stupid to live.
Too stubborn to die.

Replies are listed 'Best First'.
Re: Re: Worrying regex issue with 5.8.0
by ruscoekm (Monk) on Nov 15, 2002 at 11:14 UTC

    Thanks Tommy - saved me from submitting a duplicate bug report.

    Ok, so Data::Dumper is not the issue. Is it your understanding that any regex which uses /x and which contains a hash (even in a character class) which is not followed by a newline will potentially corrupt memory? If so, that is pretty grim. The instruction would then be:

    Before upgrading to 5.8.0, check every regex which uses /x. For each one which contains a # not followed by newline, add the text # FIXME - workaround for bug #17776->newline here

    Cheers, Kevin

      Yes, or take the spaces out, and then dump the /x modifier. If you insist on keeping the original nicely formatted with spaces, then just pump it through s/ //g before passing it to qr (which was my solution). Obviously, this needs a certain amount of care too.

      --
      Tommy
      Too stupid to live.
      Too stubborn to die.

        Yep. I am sure we'll cope :-) Thanks again for spotting this (although, as the raiser of the bug report, I am not surprised it rang a bell :-).

        Glad to have got to the end of this and to have avoided gumming up the works with a duplicate bug report.

        Cheers, Kevin