Use std::string in coff-pe-read.c
authorTom Tromey <tromey@adacore.com>
Tue, 19 Apr 2022 13:33:09 +0000 (07:33 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 22 Apr 2022 12:57:07 +0000 (06:57 -0600)
coff-pe-read.c uses xsnprintf and alloca, but using std::string is
better, and just as easy.  In general I think alloca is something to
be avoided, and unbounded uses especially so.

gdb/coff-pe-read.c

index ae4ca5435b66aaddd6b3eaf0fd5736b534e5da14..5bf0e2dc7f02d01107f2c6b5f2a3747f4bd67dd9 100644 (file)
@@ -178,16 +178,13 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
   struct bound_minimal_symbol msymbol;
   enum minimal_symbol_type msymtype;
   int forward_dll_name_len = strlen (forward_dll_name);
-  int forward_func_name_len = strlen (forward_func_name);
-  int forward_len = forward_dll_name_len + forward_func_name_len + 2;
-  char *forward_qualified_name = (char *) alloca (forward_len);
   short section;
 
-  xsnprintf (forward_qualified_name, forward_len, "%s!%s", forward_dll_name,
-            forward_func_name);
+  std::string forward_qualified_name = string_printf ("%s!%s",
+                                                     forward_dll_name,
+                                                     forward_func_name);
 
-
-  msymbol = lookup_bound_minimal_symbol (forward_qualified_name);
+  msymbol = lookup_bound_minimal_symbol (forward_qualified_name.c_str ());
 
   if (!msymbol.minsym)
     {
@@ -195,7 +192,7 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
 
       for (i = 0; i < forward_dll_name_len; i++)
        forward_qualified_name[i] = tolower (forward_qualified_name[i]);
-      msymbol = lookup_bound_minimal_symbol (forward_qualified_name);
+      msymbol = lookup_bound_minimal_symbol (forward_qualified_name.c_str ());
     }
 
   if (!msymbol.minsym)