From 25029849c3d93a3ab8c8d0db1ba24e7c91570fa5 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Sun, 7 Feb 2021 16:43:00 +0000 Subject: [PATCH] Fix RunGrepTest's handling of binary zeros on Solaris by using /usr/xpg4/bin/tr instead of tr if /usr/xpg4/bin/tr exists. --- ChangeLog | 5 ++++- RunGrepTest | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21d13b2..bcf9db8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,10 @@ Version 10.37-RC1 04-January-2021 1. Change RunGrepTest to use tr instead of sed when testing with binary zero bytes, because sed varies a lot from system to system and has problems with binary zeros. This is from Bugzilla #2681. Patch from Jeremie -Courreges-Anglas via Nam Nguyen. This fixes RunGrepTest for OpenBSD. +Courreges-Anglas via Nam Nguyen. This fixes RunGrepTest for OpenBSD. Later: +it broke it for at least one version of Solaris, where tr can't handle binary +zeros. However, that system had /usr/xpg4/bin/tr installed, which works OK, so +RunGrepTest now checks for that command and use it if found. 2. Compiling with gcc 10.2's -fanalyzer option showed up a hypothetical problem with a NULL dereference. I don't think this case could ever occur in practice, diff --git a/RunGrepTest b/RunGrepTest index 1e319c9..78206ba 100755 --- a/RunGrepTest +++ b/RunGrepTest @@ -755,16 +755,25 @@ $valgrind $vjs $pcre2grep -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep > printf '%c--------------------------- Test N6 ------------------------------\r\n' - >>testtrygrep $valgrind $vjs $pcre2grep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep -# It seems impossible to handle NUL characters easily in many operating -# systems, including Solaris (aka SunOS), where the version of sed explicitly -# doesn't like them, and also MacOS (Darwin), OpenBSD, FreeBSD, NetBSD, and -# some Linux distributions like Alpine, even when using GNU sed, so test for -# a usable sed and fudge the output so that the comparison works when sed -# doesn't. +# This next test involves NUL characters. It seems impossible to handle them +# easily in many operating systems. An earlier version of this script used sed +# to translate NUL into the string ZERO, but this didn't work on Solaris (aka +# SunOS), where the version of sed explicitly doesn't like them, and also MacOS +# (Darwin), OpenBSD, FreeBSD, NetBSD, and some Linux distributions like Alpine, +# even when using GNU sed. A user suggested using tr instead, which +# necessitates translating to a single character (@). However, on (some +# versions of?) Solaris, the normal "tr" cannot handle binary zeros, but if +# /usr/xpg4/bin/tr is available, it can do so, so test for that. + +if [ -x /usr/xpg4/bin/tr ] ; then + tr=/usr/xpg4/bin/tr +else + tr=tr +fi printf '%c--------------------------- Test N7 ------------------------------\r\n' - >>testtrygrep printf 'abc\0def' >testNinputgrep -$valgrind $vjs $pcre2grep -na --newline=nul "^(abc|def)" testNinputgrep | tr '\000' '@' >>testtrygrep +$valgrind $vjs $pcre2grep -na --newline=nul "^(abc|def)" testNinputgrep | $tr '\000' '@' >>testtrygrep echo "" >>testtrygrep $cf $srcdir/testdata/grepoutputN testtrygrep