Use std::string in mdebugread.c
authorTom Tromey <tom@tromey.com>
Sun, 22 Apr 2018 16:26:18 +0000 (10:26 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 5 Oct 2018 04:51:46 +0000 (22:51 -0600)
This changes a couple of spots in mdebugread to use std::string rather
than manual management.  This is simpler, and also avoids shadowing by
renaming the variable in question.

gdb/ChangeLog
2018-10-04  Tom Tromey  <tom@tromey.com>

* mdebugread.c (parse_partial_symbols): Use std::string.

gdb/ChangeLog
gdb/mdebugread.c

index 62840512ae34bc5f97109f5c00c19f20099eb1c9..0b5f35b2b7c9b2bf44c35927fbacb5193b46f8fb 100644 (file)
@@ -1,3 +1,7 @@
+2018-10-04  Tom Tromey  <tom@tromey.com>
+
+       * mdebugread.c (parse_partial_symbols): Use std::string.
+
 2018-10-04  Tom Tromey  <tom@tromey.com>
 
        * ctf.c (SET_ARRAY_FIELD): Rename "u32".
index 453b8d5307db9429a689c6ed59ce55cf310ed624..62de80ee1e6d73200d15ae97bdb00ba32a31b25c 100644 (file)
@@ -3197,13 +3197,9 @@ parse_partial_symbols (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 copy (namestring, p);
+                           function_outside_compilation_unit_complaint
+                             (copy.c_str ());
                          }
                        add_psymbol_to_list (namestring, p - namestring, 1,
                                             VAR_DOMAIN, LOC_BLOCK,
@@ -3220,13 +3216,9 @@ parse_partial_symbols (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 copy (namestring, p);
+                           function_outside_compilation_unit_complaint
+                             (copy.c_str ());
                          }
                        add_psymbol_to_list (namestring, p - namestring, 1,
                                             VAR_DOMAIN, LOC_BLOCK,