[Pcre-svn] [1299] code/trunk: Fix RunGrepTest' s handling of…

Etusivu
Poista viesti
Lähettäjä: Subversion repository
Päiväys:  
Vastaanottaja: pcre-svn
Aihe: [Pcre-svn] [1299] code/trunk: Fix RunGrepTest' s handling of binary zeros on Solaris by using /usr/xpg4/bin/tr
Revision: 1299
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1299
Author:   ph10
Date:     2021-02-07 16:43:00 +0000 (Sun, 07 Feb 2021)
Log Message:
-----------
Fix RunGrepTest's handling of binary zeros on Solaris by using /usr/xpg4/bin/tr 
instead of tr if /usr/xpg4/bin/tr exists.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/RunGrepTest


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2021-02-06 11:48:06 UTC (rev 1298)
+++ code/trunk/ChangeLog    2021-02-07 16:43:00 UTC (rev 1299)
@@ -7,7 +7,10 @@
 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,

Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest    2021-02-06 11:48:06 UTC (rev 1298)
+++ code/trunk/RunGrepTest    2021-02-07 16:43:00 UTC (rev 1299)
@@ -755,16 +755,25 @@
 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