Fix warning on gdb/compile/compile.c (C++-ify "triplet_rx")
authorSergio Durigan Junior <sergiodj@redhat.com>
Tue, 16 Jan 2018 19:41:17 +0000 (14:41 -0500)
committerSergio Durigan Junior <sergiodj@redhat.com>
Wed, 17 Jan 2018 23:05:42 +0000 (18:05 -0500)
This fixes a GCC warning that happens when compiling
gdb/compile/compile.c on some GCC versions (e.g., "gcc (GCC) 7.2.1
20180104 (Red Hat 7.2.1-6)"):

../../gdb/compile/compile.c: In function 'void eval_compile_command(command_line*, const char*, compile_i_scope_types, void*)':
../../gdb/compile/compile.c:548:19: warning: 'triplet_rx' may be used uninitialized in this function [-Wmaybe-uninitialized]
     error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe, triplet_rx,
     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         argc, argv);
         ~~~~~~~~~~~
../../gdb/compile/compile.c:466:9: note: 'triplet_rx' was declared here
   char *triplet_rx;
         ^~~~~~~~~~

It's a simple patch that converts "triplet_rx" from "char *" to
"std::string", thus guaranteeing that it will be always initialized.

I've regtested this patch and did not find any regressions.  OK to
apply on both master and 8.1 (after creating a bug for it)?

gdb/ChangeLog:
2018-01-17  Sergio Durigan Junior  <sergiodj@redhat.com>

* compile/compile.c (compile_to_object): Convert "triplet_rx"
to "std::string".

gdb/ChangeLog
gdb/compile/compile.c

index d1510b9fafe0f42da04dfd7ed2a7e9b331565489..79f00759659ee0f3d25492ae8e43d8a5fe3abedd 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-17  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       * compile/compile.c (compile_to_object): Convert "triplet_rx"
+       to "std::string".
+
 2018-01-17  Tom Tromey  <tom@tromey.com>
 
        * dwarf2read.c (symbolp): Remove typedef.  Don't instantiate VEC.
index 2ee75930ac5541a6d2cc2df1d6572f04e10b3fce..82e63d895f5342c63481754170d746e138ee693a 100644 (file)
@@ -463,7 +463,7 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
   char **argv;
   int ok;
   struct gdbarch *gdbarch = get_current_arch ();
-  char *triplet_rx;
+  std::string triplet_rx;
   char *error_message;
 
   if (!target_has_execution)
@@ -531,11 +531,11 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
       const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
 
       /* Allow triplets with or without vendor set.  */
-      triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL);
-      make_cleanup (xfree, triplet_rx);
+      triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx;
 
       if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
-       compiler->fe->ops->set_triplet_regexp (compiler->fe, triplet_rx);
+       compiler->fe->ops->set_triplet_regexp (compiler->fe,
+                                              triplet_rx.c_str ());
     }
 
   /* Set compiler command-line arguments.  */
@@ -545,7 +545,8 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
   if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
     error_message = compiler->fe->ops->set_arguments (compiler->fe, argc, argv);
   else
-    error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe, triplet_rx,
+    error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe,
+                                                        triplet_rx.c_str (),
                                                         argc, argv);
   if (error_message != NULL)
     {
This page took 0.027207 seconds and 4 git commands to generate.