[4/4] Use std::string in dwarf2read.c

Message ID 20200107220754.24796-5-tromey@adacore.com
State New
Headers show
Series
  • Minor DWARF memory management cleanups
Related show

Commit Message

Tom Tromey Jan. 7, 2020, 10:07 p.m.
This replaces two instances of manual string management in
dwarf2read.c with std::string.

gdb/ChangeLog
2020-01-07  Tom Tromey  <tromey@adacore.com>

	* dwarf2read.c (parse_macro_definition): Use std::string.
	(parse_macro_definition): Likewise.

Change-Id: Iec437100105484aa4a116fb5d651d7ed52ee9d81
---
 gdb/ChangeLog    |  5 +++++
 gdb/dwarf2read.c | 13 +++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)

-- 
2.21.0

Comments

Simon Marchi Jan. 8, 2020, 3:54 a.m. | #1
On 2020-01-07 5:07 p.m., Tom Tromey wrote:
> This replaces two instances of manual string management in

> dwarf2read.c with std::string.

> 

> gdb/ChangeLog

> 2020-01-07  Tom Tromey  <tromey@adacore.com>

> 

> 	* dwarf2read.c (parse_macro_definition): Use std::string.

> 	(parse_macro_definition): Likewise.

> 

> Change-Id: Iec437100105484aa4a116fb5d651d7ed52ee9d81


Thanks, this LGTM.

Simon

Patch

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index ad361df00b9..be03150b8db 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -24578,7 +24578,7 @@  parse_macro_definition (struct macro_source_file *file, int line,
     {
       /* It's an object-like macro.  */
       int name_len = p - body;
-      char *name = savestring (body, name_len);
+      std::string name (body, name_len);
       const char *replacement;
 
       if (*p == ' ')
@@ -24589,14 +24589,12 @@  parse_macro_definition (struct macro_source_file *file, int line,
           replacement = body + name_len;
         }
 
-      macro_define_object (file, line, name, replacement);
-
-      xfree (name);
+      macro_define_object (file, line, name.c_str (), replacement);
     }
   else if (*p == '(')
     {
       /* It's a function-like macro.  */
-      char *name = savestring (body, p - body);
+      std::string name (body, p - body);
       int argc = 0;
       int argv_size = 1;
       char **argv = XNEWVEC (char *, argv_size);
@@ -24645,14 +24643,14 @@  parse_macro_definition (struct macro_source_file *file, int line,
 
           if (*p == ' ')
             /* Perfectly formed definition, no complaints.  */
-            macro_define_function (file, line, name,
+            macro_define_function (file, line, name.c_str (),
                                    argc, (const char **) argv,
                                    p + 1);
           else if (*p == '\0')
             {
               /* Complain, but do define it.  */
 	      dwarf2_macro_malformed_definition_complaint (body);
-              macro_define_function (file, line, name,
+              macro_define_function (file, line, name.c_str (),
                                      argc, (const char **) argv,
                                      p);
             }
@@ -24664,7 +24662,6 @@  parse_macro_definition (struct macro_source_file *file, int line,
         /* Just complain.  */
 	dwarf2_macro_malformed_definition_complaint (body);
 
-      xfree (name);
       {
         int i;