]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
In the "Command:" line in the preamble, escape special chars such as ' ' and
authorNicholas Nethercote <njn@valgrind.org>
Sun, 2 Aug 2009 23:03:06 +0000 (23:03 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sun, 2 Aug 2009 23:03:06 +0000 (23:03 +0000)
'\\'.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10690

coregrind/m_main.c
none/tests/Makefile.am

index 6e33e77a3b3dfa6aee37a0229b16d98d1d4a2a86..8e3fb468e42d36ae8f83c5255660c16c669c2979 100644 (file)
@@ -958,6 +958,21 @@ static void print_file_vars(Char* format)
 /*=== Printing the preamble                                        ===*/
 /*====================================================================*/
 
+// Print the command, escaping any chars that require it.
+static void umsg_or_xml_arg(Char* arg,
+                            UInt (*umsg_or_xml)( const HChar*, ... ) )
+{
+   SizeT len = VG_(strlen)(arg);
+   Char* special = " \\<>";
+   Int i;
+   for (i = 0; i < len; i++) {
+      if (VG_(strchr)(special, arg[i])) {
+         umsg_or_xml("\\");   // escape with a backslash if necessary
+      }
+      umsg_or_xml("%c", arg[i]);
+   }
+}
+
 /* Ok, the logging sink is running now.  Print a suitable preamble.
    If logging to file or a socket, write details of parent PID and
    command line args, to help people trying to interpret the
@@ -1030,7 +1045,7 @@ static void print_preamble ( Bool logging_to_fd,
       */
       umsg_or_xml("Command: ");
       if (VG_(args_the_exename))
-         umsg_or_xml("%s", VG_(args_the_exename));
+         umsg_or_xml_arg(VG_(args_the_exename), umsg_or_xml);
       n = 0;
       for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
          HChar* s = *(HChar**)VG_(indexXA)( VG_(args_for_client), i );
@@ -1043,7 +1058,8 @@ static void print_preamble ( Bool logging_to_fd,
             VG_(umsg)("\n        ");
             n = slen;
          }
-         umsg_or_xml(" %s", s);
+         umsg_or_xml(" ");
+         umsg_or_xml_arg(s, umsg_or_xml);
       }
       umsg_or_xml("\n");
 
index cb85e3c32a7b843d218947218e91e79d1b0fa6ae..92b1caaf199eddeea3cbe68cd72e597b11866010 100644 (file)
@@ -57,6 +57,7 @@ EXTRA_DIST = \
        cmdline4.stderr.exp cmdline4.vgtest \
        cmdline5.stderr.exp cmdline5.vgtest \
        cmdline6.stderr.exp cmdline6.vgtest \
+       cmd-with-special.stderr.exp cmd-with-special.vgtest \
        coolo_sigaction.stderr.exp \
        coolo_sigaction.stdout.exp coolo_sigaction.vgtest \
        coolo_strlen.stderr.exp coolo_strlen.vgtest \