Skip to content

Commit 45d2a45

Browse files
author
weidendo
committed
Fix Bug #344314 callgrind_annotate ... commands containing newlines
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 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent c157b43 commit 45d2a45

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ where XXXXXX is the bug number as listed below.
101101
344279 syscall sendmmsg on arm64 (269) and ppc32/64 (349) unhandled
102102
344295 syscall recvmmsg on arm64 (243) and ppc32/64 (343) unhandled
103103
344307 2 unhandled syscalls on aarch64/arm64: umount2(39), mount (40)
104+
344314 callgrind_annotate ... warnings about commands containing newlines
104105
n-i-bz Provide implementations of certain compiler builtins to support
105106
compilers who may not provide those
106107
n-i-bz Old STABS code is still being compiled, but never used. Remove it.

callgrind/dump.c

+22-2
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,15 @@ void init_cmdbuf(void)
15081508
for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
15091509
const HChar *arg = *(HChar**)VG_(indexXA)( VG_(args_for_client), i );
15101510
size += 1; // separator ' '
1511-
size += VG_(strlen)(arg);
1511+
// escape NL in arguments to not break dump format
1512+
for(j=0; arg[j]; j++)
1513+
switch(arg[j]) {
1514+
case '\n':
1515+
case '\\':
1516+
size++; // fall through
1517+
default:
1518+
size++;
1519+
}
15121520
}
15131521

15141522
cmdbuf = CLG_MALLOC("cl.dump.ic.1", size + 1); // +1 for '\0'
@@ -1520,7 +1528,19 @@ void init_cmdbuf(void)
15201528
const HChar *arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
15211529
cmdbuf[size++] = ' ';
15221530
for(j=0; arg[j]; j++)
1523-
cmdbuf[size++] = arg[j];
1531+
switch(arg[j]) {
1532+
case '\n':
1533+
cmdbuf[size++] = '\\';
1534+
cmdbuf[size++] = 'n';
1535+
break;
1536+
case '\\':
1537+
cmdbuf[size++] = '\\';
1538+
cmdbuf[size++] = '\\';
1539+
break;
1540+
default:
1541+
cmdbuf[size++] = arg[j];
1542+
break;
1543+
}
15241544
}
15251545
cmdbuf[size] = '\0';
15261546
}

0 commit comments

Comments
 (0)