[3/8] Use std::string in mdebugread.c

Message ID 20180923040814.27941-4-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 23, 2018, 4:08 a.m. UTC
  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-09-22  Tom Tromey  <tom@tromey.com>

	* mdebugread.c (parse_partial_symbols): Use std::string.
---
 gdb/ChangeLog    |  4 ++++
 gdb/mdebugread.c | 20 ++++++--------------
 2 files changed, 10 insertions(+), 14 deletions(-)
  

Comments

Kevin Buettner Oct. 12, 2018, 4:27 a.m. UTC | #1
On Sat, 22 Sep 2018 22:08:09 -0600
Tom Tromey <tom@tromey.com> wrote:

> 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-09-22  Tom Tromey  <tom@tromey.com>
> 
> 	* mdebugread.c (parse_partial_symbols): Use std::string.

You're right, it is simpler.

LGTM.

Kevin
  

Patch

diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 4c433da99f..d959a09ee7 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -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,