]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert char array to std::string in linux_find_memory_regions_full
authorLuis Machado <luis.machado@linaro.org>
Wed, 30 Dec 2020 13:46:11 +0000 (10:46 -0300)
committerLuis Machado <luis.machado@linaro.org>
Tue, 25 May 2021 01:13:44 +0000 (22:13 -0300)
This is a quick cleanup that removes the use of fixed-length char arrays and
uses std::string instead.

gdb/ChangeLog:

2021-03-24  Luis Machado  <luis.machado@linaro.org>

* linux-tdep.c (linux_find_memory_regions_full): Use std::string
instead of char arrays.

gdb/ChangeLog
gdb/linux-tdep.c

index a5f8f6d21f867e7f8d8c7b7d223b7e075f753369..a24f071057f8e2270509f70cd9673df706eb4bcb 100644 (file)
@@ -1,3 +1,12 @@
+2021-05-04  Luis Machado  <luis.machado@arm.com>
+
+       Cherry-picked from GDB master
+
+       2021-03-24  Luis Machado  <luis.machado@linaro.org>
+
+       * linux-tdep.c (linux_find_memory_regions_full): Use std::string
+       instead of char arrays.
+
 2021-04-27  Luis Machado  <luis.machado@arm.com>
 
        * aarch64-tdep.c (struct stack_item_t) <arg_value): New field.
index 439f583a8027ce6c28568196da47a6963042e4e6..2d69635421f6e925ba1927c128737cf5d6c30a64 100644 (file)
@@ -1276,8 +1276,6 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
                                linux_find_memory_region_ftype *func,
                                void *obfd)
 {
-  char mapsfilename[100];
-  char coredumpfilter_name[100];
   pid_t pid;
   /* Default dump behavior of coredump_filter (0x33), according to
      Documentation/filesystems/proc.txt from the Linux kernel
@@ -1295,10 +1293,12 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
 
   if (use_coredump_filter)
     {
-      xsnprintf (coredumpfilter_name, sizeof (coredumpfilter_name),
-                "/proc/%d/coredump_filter", pid);
+      std::string core_dump_filter_name
+       = string_printf ("/proc/%d/coredump_filter", pid);
+
       gdb::unique_xmalloc_ptr<char> coredumpfilterdata
-       = target_fileio_read_stralloc (NULL, coredumpfilter_name);
+       = target_fileio_read_stralloc (NULL, core_dump_filter_name.c_str ());
+
       if (coredumpfilterdata != NULL)
        {
          unsigned int flags;
@@ -1308,14 +1308,16 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
        }
     }
 
-  xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/smaps", pid);
+  std::string maps_filename = string_printf ("/proc/%d/smaps", pid);
+
   gdb::unique_xmalloc_ptr<char> data
-    = target_fileio_read_stralloc (NULL, mapsfilename);
+    = target_fileio_read_stralloc (NULL, maps_filename.c_str ());
+
   if (data == NULL)
     {
       /* Older Linux kernels did not support /proc/PID/smaps.  */
-      xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/maps", pid);
-      data = target_fileio_read_stralloc (NULL, mapsfilename);
+      maps_filename = string_printf ("/proc/%d/maps", pid);
+      data = target_fileio_read_stralloc (NULL, maps_filename.c_str ());
     }
 
   if (data != NULL)
@@ -1375,7 +1377,8 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
 
              if (sscanf (line, "%64s", keyword) != 1)
                {
-                 warning (_("Error parsing {s,}maps file '%s'"), mapsfilename);
+                 warning (_("Error parsing {s,}maps file '%s'"),
+                          maps_filename.c_str ());
                  break;
                }
 
@@ -1396,7 +1399,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
                  if (sscanf (line, "%*s%lu", &number) != 1)
                    {
                      warning (_("Error parsing {s,}maps file '%s' number"),
-                              mapsfilename);
+                              maps_filename.c_str ());
                      break;
                    }
                  if (number > 0)