|
From: <sv...@va...> - 2014-10-01 14:16:12
|
Author: florian
Date: Wed Oct 1 15:16:05 2014
New Revision: 14597
Log:
Merge revisions 14337, 14596 from the BUF_REMOVAL branch to trunk.
Change callgrind's init_cmdbuf function to allocate a large enough
buffer for the command line.
Modified:
trunk/ (props changed)
trunk/callgrind/dump.c
Modified: trunk/callgrind/dump.c
==============================================================================
--- trunk/callgrind/dump.c (original)
+++ trunk/callgrind/dump.c Wed Oct 1 15:16:05 2014
@@ -40,7 +40,7 @@
static Bool dumps_initialized = False;
/* Command */
-static HChar cmdbuf[BUF_LEN];
+static HChar *cmdbuf;
/* Total reads/writes/misses sum over all dumps and threads.
* Updated during CC traversal at dump time.
@@ -1618,22 +1618,30 @@
static
void init_cmdbuf(void)
{
- Int i,j,size = 0;
- HChar* argv;
+ SizeT size;
+ Int i,j;
- CLG_ASSERT( VG_(strlen)( VG_(args_the_exename) ) < BUF_LEN-1);
+ /* Pass #1: How many bytes do we need? */
+ size = 1; // leading ' '
+ size += VG_(strlen)( VG_(args_the_exename) );
+ 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);
+ }
+
+ cmdbuf = CLG_MALLOC("cl.dump.ic.1", size + 1); // +1 for '\0'
+
+ /* Pass #2: Build up the string */
size = VG_(sprintf)(cmdbuf, " %s", VG_(args_the_exename));
for(i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
- argv = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
- if (!argv) continue;
- if ((size>0) && (size < BUF_LEN)) cmdbuf[size++] = ' ';
- for(j=0;argv[j]!=0;j++)
- if (size < BUF_LEN) cmdbuf[size++] = argv[j];
+ const HChar *arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
+ cmdbuf[size++] = ' ';
+ for(j=0; arg[j]; j++)
+ cmdbuf[size++] = arg[j];
}
-
- if (size >= BUF_LEN) size = BUF_LEN-1;
- cmdbuf[size] = 0;
+ cmdbuf[size] = '\0';
}
/*
|