gdb: make use of std::string in dbxread.c and xcoffread.c

While taking a look through dbxread.c I spotted a couple of places
where making use of std::string would remove the need for manual
memory allocation and memcpy.

During review Simon pointed out that the same code exists in
xcoffread.c, so I've applied the same fix there too.

There should be no user visible changes after this commit.
This commit is contained in:
Andrew Burgess 2022-02-19 13:08:32 +00:00
parent dc5483c989
commit 9c6c44713f
2 changed files with 8 additions and 28 deletions

View File

@ -1603,13 +1603,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
case 'f':
if (! pst)
{
int name_len = p - namestring;
char *name = (char *) xmalloc (name_len + 1);
memcpy (name, namestring, name_len);
name[name_len] = '\0';
function_outside_compilation_unit_complaint (name);
xfree (name);
std::string name (namestring, (p - namestring));
function_outside_compilation_unit_complaint (name.c_str ());
}
/* Kludges for ELF/STABS with Sun ACC. */
last_function_name = namestring;
@ -1663,13 +1658,8 @@ read_dbx_symtab (minimal_symbol_reader &reader,
case 'F':
if (! pst)
{
int name_len = p - namestring;
char *name = (char *) xmalloc (name_len + 1);
memcpy (name, namestring, name_len);
name[name_len] = '\0';
function_outside_compilation_unit_complaint (name);
xfree (name);
std::string name (namestring, (p - namestring));
function_outside_compilation_unit_complaint (name.c_str ());
}
/* Kludges for ELF/STABS with Sun ACC. */
last_function_name = namestring;

View File

@ -2734,13 +2734,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
case 'f':
if (! pst)
{
int name_len = p - namestring;
char *name = (char *) xmalloc (name_len + 1);
memcpy (name, namestring, name_len);
name[name_len] = '\0';
function_outside_compilation_unit_complaint (name);
xfree (name);
std::string name (namestring, (p - namestring));
function_outside_compilation_unit_complaint (name.c_str ());
}
pst->add_psymbol (gdb::string_view (namestring,
p - namestring),
@ -2758,13 +2753,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
case 'F':
if (! pst)
{
int name_len = p - namestring;
char *name = (char *) xmalloc (name_len + 1);
memcpy (name, namestring, name_len);
name[name_len] = '\0';
function_outside_compilation_unit_complaint (name);
xfree (name);
std::string name (namestring, (p - namestring));
function_outside_compilation_unit_complaint (name.c_str ());
}
/* We need only the minimal symbols for these