[binutils-gdb] Use std::string in memory_map_parsing_data

Simon Marchi simark@sourceware.org
Sat Oct 21 16:17:00 GMT 2017


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6e17c56511104abd605bd2d122104467fc4f0089

commit 6e17c56511104abd605bd2d122104467fc4f0089
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Sat Oct 21 12:06:22 2017 -0400

    Use std::string in memory_map_parsing_data
    
    Replace the fixed-size array with a string.
    
    gdb/ChangeLog:
    
    	* memory-map.c (struct memory_map_parsing_data) <property_name>:
    	Change type to std::string.
    	(memory_map_start_property): Adjust.
    	(memory_map_end_property): Adjust.

Diff:
---
 gdb/ChangeLog    |  7 +++++++
 gdb/memory-map.c | 17 +++++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e440989..ecb73d9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2017-10-21  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* memory-map.c (struct memory_map_parsing_data) <property_name>:
+	Change type to std::string.
+	(memory_map_start_property): Adjust.
+	(memory_map_end_property): Adjust.
+
 2017-10-21  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* infrun.h: Include common/byte-vector.h.
diff --git a/gdb/memory-map.c b/gdb/memory-map.c
index 0b21456..ff05394 100644
--- a/gdb/memory-map.c
+++ b/gdb/memory-map.c
@@ -43,10 +43,11 @@ parse_memory_map (const char *memory_map)
 
 /* Internal parsing data passed to all XML callbacks.  */
 struct memory_map_parsing_data
-  {
-    VEC(mem_region_s) **memory_map;
-    char property_name[32];
-  };
+{
+  VEC(mem_region_s) **memory_map;
+
+  std::string property_name;
+};
 
 /* Handle the start of a <memory> element.  */
 
@@ -103,7 +104,7 @@ memory_map_start_property (struct gdb_xml_parser *parser,
   char *name;
 
   name = (char *) xml_find_attribute (attributes, "name")->value;
-  snprintf (data->property_name, sizeof (data->property_name), "%s", name);
+  data->property_name.assign (name);
 }
 
 /* Handle the end of a <property> element and its value.  */
@@ -115,16 +116,16 @@ memory_map_end_property (struct gdb_xml_parser *parser,
 {
   struct memory_map_parsing_data *data
     = (struct memory_map_parsing_data *) user_data;
-  char *name = data->property_name;
 
-  if (strcmp (name, "blocksize") == 0)
+  if (data->property_name == "blocksize")
     {
       struct mem_region *r = VEC_last (mem_region_s, *data->memory_map);
 
       r->attrib.blocksize = gdb_xml_parse_ulongest (parser, body_text);
     }
   else
-    gdb_xml_debug (parser, _("Unknown property \"%s\""), name);
+    gdb_xml_debug (parser, _("Unknown property \"%s\""),
+		   data->property_name.c_str ());
 }
 
 /* Discard the constructed memory map (if an error occurs).  */



More information about the Gdb-cvs mailing list