|
From: <sv...@va...> - 2014-08-22 20:18:12
|
Author: florian
Date: Fri Aug 22 20:18:04 2014
New Revision: 14337
Log:
Rewrite init_cmdbuf to dynamically allocate a large enough buffer
to hold the client's commandline.
Also eliminate the check that a client arg could be NULL. This cannot
be (see VG_(split_up_argv) ).
Modified:
branches/BUF_REMOVAL/callgrind/dump.c
Modified: branches/BUF_REMOVAL/callgrind/dump.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/dump.c (original)
+++ branches/BUF_REMOVAL/callgrind/dump.c Fri Aug 22 20:18:04 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.
@@ -1616,22 +1616,31 @@
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);
+ }
+ size += 1; // '\0'
+
+ cmdbuf = CLG_MALLOC("cl.dump.ic.1", size);
+
+ /* 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';
}
/*
|