]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix Bug #344314 callgrind_annotate ... commands containing newlines
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Wed, 18 Feb 2015 16:28:58 +0000 (16:28 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Wed, 18 Feb 2015 16:28:58 +0000 (16:28 +0000)
Escape newlines in command arguments for "cmd:" header field in dumps
We could do unescaping in callgrind_annotate, but a escaped command
even seems better there.

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

NEWS
callgrind/dump.c

diff --git a/NEWS b/NEWS
index 3e6dbe520d6f4aac375e92705aa7e18e86c037ed..8c8b7c537e193771570e486db28af1144d3f0a47 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -101,6 +101,7 @@ where XXXXXX is the bug number as listed below.
 344279  syscall sendmmsg on arm64 (269) and ppc32/64 (349) unhandled
 344295  syscall recvmmsg on arm64 (243) and ppc32/64 (343) unhandled
 344307  2 unhandled syscalls on aarch64/arm64: umount2(39), mount (40)
+344314  callgrind_annotate ... warnings about commands containing newlines
 n-i-bz  Provide implementations of certain compiler builtins to support
         compilers who may not provide those
 n-i-bz  Old STABS code is still being compiled, but never used. Remove it.
index 687561431b08fefab0fda8a2b149ffa1331c6658..c6d4de11bd3c1bed3ebc4a0f2d1d79452a4acc29 100644 (file)
@@ -1508,7 +1508,15 @@ void init_cmdbuf(void)
   for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
      const HChar *arg = *(HChar**)VG_(indexXA)( VG_(args_for_client), i );
      size += 1;   // separator ' '
-     size += VG_(strlen)(arg);
+     // escape NL in arguments to not break dump format
+     for(j=0; arg[j]; j++)
+       switch(arg[j]) {
+       case '\n':
+       case '\\':
+        size++; // fall through
+       default:
+        size++;
+       }
   }
 
   cmdbuf = CLG_MALLOC("cl.dump.ic.1", size + 1);  // +1 for '\0'
@@ -1520,7 +1528,19 @@ void init_cmdbuf(void)
      const HChar *arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
      cmdbuf[size++] = ' ';
      for(j=0; arg[j]; j++)
-        cmdbuf[size++] = arg[j];
+       switch(arg[j]) {
+       case '\n':
+        cmdbuf[size++] = '\\';
+        cmdbuf[size++] = 'n';
+        break;
+       case '\\':
+        cmdbuf[size++] = '\\';
+        cmdbuf[size++] = '\\';
+        break;
+       default:
+        cmdbuf[size++] = arg[j];
+        break;
+       }
   }
   cmdbuf[size] = '\0';
 }