Remove two fixed-size buffers in the dwarf readers.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14820 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_debuginfo/readdwarf.c b/coregrind/m_debuginfo/readdwarf.c
index ec6fd49..66ffd93 100644
--- a/coregrind/m_debuginfo/readdwarf.c
+++ b/coregrind/m_debuginfo/readdwarf.c
@@ -518,35 +518,33 @@
while (ML_(cur_read_UChar)(data) != 0) {
-# define NBUF 4096
- static HChar buf[NBUF];
-
HChar* data_str = ML_(cur_read_strdup)(data, "di.rd2l.1");
if (di->ddump_line)
VG_(printf)(" %s\n", data_str);
/* If data[0] is '/', then 'data' is an absolute path and we
- don't mess with it. Otherwise, if we can, construct the
+ don't mess with it. Otherwise, construct the
path 'ui->compdir' ++ "/" ++ 'data'. */
if (data_str[0] != '/'
/* not an absolute path */
&& ML_(cur_is_valid)(ui->compdir)
/* actually got something sensible for compdir */
- && ML_(cur_strlen)(ui->compdir)
- + VG_(strlen)(data_str) + 5/*paranoia*/ < NBUF
- /* it's short enough to concatenate */)
+ && ML_(cur_strlen)(ui->compdir))
{
- buf[0] = 0;
HChar* compdir_str = ML_(cur_read_strdup)(ui->compdir, "di.rd2l.1b");
- VG_(strcat)(buf, compdir_str);
+ SizeT len = VG_(strlen)(compdir_str) + 1 + VG_(strlen)(data_str);
+ HChar *buf = ML_(dinfo_zalloc)("di.rd2l.1c", len + 1);
+
+ VG_(strcpy)(buf, compdir_str);
VG_(strcat)(buf, "/");
VG_(strcat)(buf, data_str);
- vg_assert(VG_(strlen)(buf) < NBUF);
- dirname = ML_(addStr)(di,buf,-1);
+
+ dirname = ML_(addStr)(di, buf, len);
VG_(addToXA) (dirname_xa, &dirname);
if (0) VG_(printf)("rel path %s\n", buf);
ML_(dinfo_free)(compdir_str);
+ ML_(dinfo_free)(buf);
} else {
/* just use 'data'. */
dirname = ML_(addStr)(di,data_str,-1);
@@ -556,8 +554,6 @@
data = ML_(cur_plus)(data, VG_(strlen)(data_str) + 1);
ML_(dinfo_free)(data_str);
-
-# undef NBUF
}
if (di->ddump_line)
diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c
index 4be1762..d89af4f 100644
--- a/coregrind/m_debuginfo/readdwarf3.c
+++ b/coregrind/m_debuginfo/readdwarf3.c
@@ -1794,14 +1794,14 @@
{
XArray* dirname_xa; /* xarray of HChar* dirname */
const HChar* dirname;
- UInt compdir_len = 0;
+ UInt compdir_len;
dirname_xa = VG_(newXA) (ML_(dinfo_zalloc), "di.rdxa.1", ML_(dinfo_free),
sizeof(HChar*) );
if (compdir == NULL) {
dirname = ".";
- compdir_len = 0;
+ compdir_len = 1;
} else {
dirname = compdir;
compdir_len = VG_(strlen)(compdir);
@@ -1813,32 +1813,31 @@
while (peek_UChar(c) != 0) {
-# define NBUF 4096
- static HChar buf[NBUF];
DiCursor cur = get_AsciiZ(c);
HChar* data_str = ML_(cur_read_strdup)( cur, "dirname_xa.1" );
TRACE_D3(" %s\n", data_str);
/* If data_str[0] is '/', then 'data' is an absolute path and we
- don't mess with it. Otherwise, if we can, construct the
+ don't mess with it. Otherwise, construct the
path 'compdir' ++ "/" ++ 'data'. */
if (data_str[0] != '/'
/* not an absolute path */
&& compdir
/* actually got something sensible for compdir */
- && compdir_len
- + VG_(strlen)(data_str) + 5/*paranoia*/ < NBUF
- /* it's short enough to concatenate */)
+ && compdir_len)
{
- buf[0] = 0;
- VG_(strcat)(buf, compdir);
+ SizeT len = compdir_len + 1 + VG_(strlen)(data_str);
+ HChar *buf = ML_(dinfo_zalloc)("dirname_xa.2", len + 1);
+
+ VG_(strcpy)(buf, compdir);
VG_(strcat)(buf, "/");
VG_(strcat)(buf, data_str);
- vg_assert(VG_(strlen)(buf) < NBUF);
- dirname = ML_(addStr)(di,buf,-1);
+
+ dirname = ML_(addStr)(di, buf, len);
VG_(addToXA) (dirname_xa, &dirname);
if (0) VG_(printf)("rel path %s\n", buf);
+ ML_(dinfo_free)(buf);
} else {
/* just use 'data'. */
dirname = ML_(addStr)(di,data_str,-1);
@@ -1847,8 +1846,6 @@
}
ML_(dinfo_free)(data_str);
-
-# undef NBUF
}
TRACE_D3 ("\n");