dg-cmp-results: Escape slash from variant argument

Message ID 20230811081023.95408-1-mikael@gcc.gnu.org
State Accepted
Headers
Series dg-cmp-results: Escape slash from variant argument |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Mikael Morin Aug. 11, 2023, 8:10 a.m. UTC
  Hello,

I ran into a bug recently, running dg-cmp-results.sh with variant
unix/-m32.  This fixes it.

OK for master?

-- >8 --

Escape slash characters in $header variable (coming from the variant
argument).  This avoids runs with say "unix/-m32" as variant resulting
in sed errors "unknown command: -".

contrib/ChangeLog:

	* dg-cmp-results.sh: Escape slashes in $header to a new
	variable.  Use the new variable in sed command.
---
 contrib/dg-cmp-results.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Patch

diff --git a/contrib/dg-cmp-results.sh b/contrib/dg-cmp-results.sh
index 33e0605dc50..7d17772dc75 100755
--- a/contrib/dg-cmp-results.sh
+++ b/contrib/dg-cmp-results.sh
@@ -90,8 +90,11 @@  sed $E -e '/^[[:space:]]+===/,$d' $OFILE
 echo "Newer log file: $NFILE"
 sed $E -e '/^[[:space:]]+===/,$d' $NFILE
 
+# Escape occurences of / in $header before passing through sed.
+header_pattern=`echo "$header" | sed $E -e 's:/:[/]:g'`
+
 # Create a temporary file from the old file's interesting section.
-sed $E -e "/$header/,/^[[:space:]]+===.*Summary ===/!d" \
+sed $E -e "/$header_pattern/,/^[[:space:]]+===.*Summary ===/!d" \
   -e '/^[A-Z]+:/!d' \
   -e '/^(WARNING|ERROR):/d' \
   -e 's/\r$//' \
@@ -101,7 +104,7 @@  sed $E -e "/$header/,/^[[:space:]]+===.*Summary ===/!d" \
   >$TMPDIR/o$$-$OBASE
 
 # Create a temporary file from the new file's interesting section.
-sed $E -e "/$header/,/^[[:space:]]+===.*Summary ===/!d" \
+sed $E -e "/$header_pattern/,/^[[:space:]]+===.*Summary ===/!d" \
   -e '/^[A-Z]+:/!d' \
   -e '/^(WARNING|ERROR):/d' \
   -e 's/\r$//' \