gdb: make use of std::string in dbxread.c and xcoffread.c
authorAndrew Burgess <aburgess@redhat.com>
Sat, 19 Feb 2022 13:08:32 +0000 (13:08 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 21 Feb 2022 11:40:39 +0000 (11:40 +0000)
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.

gdb/dbxread.c
gdb/xcoffread.c

index 911d518b7e9413bd33914158d7b4296785bbf01b..ddda5df4ee161b2de28f05a33ee723e0d07737bd 100644 (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;
index d3e9ade72cb57768b61d3dd374ed482ce38b27c7..f6db7f9ff7e4481c2873119ea667775f24c57c3f 100644 (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