From: Florian Krohm Date: Wed, 1 Oct 2014 14:16:05 +0000 (+0000) Subject: Merge revisions 14337, 14596 from the BUF_REMOVAL branch to trunk. X-Git-Tag: svn/VALGRIND_3_11_0~945 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3065f2e199522313aa650a841e179b1c7acae31d;p=thirdparty%2Fvalgrind.git 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. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14597 --- diff --git a/callgrind/dump.c b/callgrind/dump.c index f7edc413e0..5e73a9f459 100644 --- a/callgrind/dump.c +++ b/callgrind/dump.c @@ -40,7 +40,7 @@ static HChar* out_file = 0; 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 @@ void CLG_(dump_profile)(const HChar* trigger, Bool only_current_thread) static void init_cmdbuf(void) { - Int i,j,size = 0; - HChar* argv; + SizeT size; + Int i,j; + + /* 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' - CLG_ASSERT( VG_(strlen)( VG_(args_the_exename) ) < BUF_LEN-1); + /* 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'; } /*