Subject: bug#22655: grep -Pz '^' now fails!

From: Zev Weiss <[email-masked]>
Date: Sat, 19 Nov 2016 03:22:07 -0600

On Sat, Nov 19, 2016 at 12:36:12AM -0800, Paul Eggert wrote:
>Stephane Chazelas wrote:
>>one can
>>use (?m) if he wants ^ to match the beginning of each line in
>>the NUL-delimited record instead of just the beginning of the
>>record.
>
>I think the intent is that ^ and $ should match only the 
>line-terminator specified by -z (or by -z's absence). So the sort of 
>usage you describe is unspecified and not supported. That being said, 
>it does make sense to match tricky regular expressions like that line 
>by line, even if this hurts performance. Otherwise, I suspect there 
>are even trickier regular expressions that could reject a buffer full 
>of lines even though it contains matching lines. When in doubt we 
>should avoid optimization so I installed the attached patch into the 
>master branch. Please give it a try.

>>From 0e00fe0fc34184b1cdcea92a671eb9ffebb4899b Mon Sep 17 00:00:00 2001
>From: Paul Eggert <[email-masked]>
>Date: Sat, 19 Nov 2016 00:25:46 -0800
>Subject: [PATCH] grep: -Pz no longer rejects ^, $
>
>Problem reported by Stephane Chazelas (Bug#22655).
>* NEWS: Document this.
>* doc/grep.texi (grep Programs): Warn about -Pz.
>* src/pcresearch.c (reflags): New static var.
>(multibyte_locale): Remove static var; now local to Pcompile.
>(Pcompile): Check for (? and (* too.  Set reflags instead of
>dying when problematic operators are found.
>(Pexecute): Use reflags to decide whether searches should
>be multiline.
>* tests/pcre: Test new behavior.

I'm a bit confused by this patch -- I see 'reflags' being tested in 
Pexecute(), but I don't see it getting set anywhere, just Pcompile()'s 
local 'flags'...I'm guessing 'flags' was supposed to be replaced by 
'reflags'?  (Not entirely certain though.)

Zev