|
From: <sv...@va...> - 2014-08-24 20:56:19
|
Author: florian
Date: Sun Aug 24 20:56:12 2014
New Revision: 14355
Log:
Get rid of fixed size buffer in mangled_cxt.
Update the FIXME at the call site.
Modified:
branches/BUF_REMOVAL/callgrind/bbcc.c
branches/BUF_REMOVAL/callgrind/global.h
Modified: branches/BUF_REMOVAL/callgrind/bbcc.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/bbcc.c (original)
+++ branches/BUF_REMOVAL/callgrind/bbcc.c Sun Aug 24 20:56:12 2014
@@ -338,18 +338,26 @@
current_bbccs.entries);
}
-static const HChar* mangled_cxt(Context* cxt, int rec_index)
+/* String is returned in a dynamically allocated buffer. Caller is
+ responsible for free'ing it. */
+static HChar* mangled_cxt(Context* cxt, Int rec_index)
{
- static HChar mangled[FN_NAME_LEN];
- int i, p;
+ SizeT size = 200;
+ HChar *mangled = CLG_MALLOC("cl.bbcc.mcxt", size);
+ Int i, p;
- if (!cxt) return "(no context)";
+ if (!cxt) return VG_(strcpy)(mangled, "(no context)");
+ grow_buffer(&mangled, &size, VG_(strlen)(cxt->fn[0]->name) + 1);
p = VG_(sprintf)(mangled, "%s", cxt->fn[0]->name);
- if (rec_index >0)
+ if (rec_index >0) {
+ grow_buffer(&mangled, &size, p + 1 + 11 + 1);
p += VG_(sprintf)(mangled+p, "'%d", rec_index +1);
- for(i=1;i<cxt->size;i++)
+ }
+ for(i=1;i<cxt->size;i++) {
+ grow_buffer(&mangled, &size, p + 1 + VG_(strlen)(cxt->fn[i]->name) + 1);
p += VG_(sprintf)(mangled+p, "'%s", cxt->fn[i]->name);
+ }
return mangled;
}
@@ -413,8 +421,8 @@
CLG_DEBUGIF(3)
CLG_(print_bbcc)(-2, bbcc);
- // FIXME: mangled_cxt returns a pointer to a static buffer that
- // gets overwritten with each invocation.
+ // FIXME: mangled_cxt returns a pointer to a dynamically allocated buffer
+ // that should be freed.
CLG_DEBUG(2,"- clone_BBCC(%p, %d) for BB %#lx\n"
" orig %s\n"
" new %s\n",
Modified: branches/BUF_REMOVAL/callgrind/global.h
==============================================================================
--- branches/BUF_REMOVAL/callgrind/global.h (original)
+++ branches/BUF_REMOVAL/callgrind/global.h Sun Aug 24 20:56:12 2014
@@ -128,7 +128,6 @@
#define MIN_LINE_SIZE 16
/* Size of various buffers used for storing strings */
-#define FN_NAME_LEN 4096 /* for C++ code :-) */
#define BUF_LEN 512
#define RESULTS_BUF_LEN 256
|