Subject: some patterns which should match 0x0 don’t do so

From: Christoph Anton Mitterer <[email-masked]>
Date: Sun, 07 Nov 2021 17:56:56 +0100

Hey.

Maybe this is no a bug at all due grep rather being focused on text
files and 0x0 being special anyway, but just for your information:

$ hd test-with-0x00-and-0x02 
00000000  66 6f 6f 0a 62 61 72 0a  7a 65 02 00 0a 62 61 7a  |foo.bar.ze...baz|
00000010  0a 7a 65 72 00 0a 65 6e  64 0a                    |.zer..end.|
0000001a

If one now does:
$ grep '[^[:alnum:][:space:][:punct:]]' test-with-0x00-and-0x02
grep: test-with-0x00-and-0x02: binary file matches

it matches, presumably only the 0x02, though.

Having only 0x00 in the file:
$ hd test-with-0x00-only
00000000  66 6f 6f 0a 62 61 72 0a  7a 65 72 00 0a 62 61 7a  |foo.bar.zer..baz|
00000010  0a 7a 65 72 00 0a 65 6e  64 0a                    |.zer..end.|
0000001a

doesn’t cause a match:
$ grep '[^[:alnum:][:space:][:punct:]]' test-with-0x00-only
$

while naively I'd have assume that 0x00 should be matched as well.

Cheers,
Chris.