This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] -Wwrite-strings: Constify shell_escape and plug make_command leak


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

commit be47f9e8180d7275b0e2b26998472e99be9a2d7b
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Apr 5 19:21:34 2017 +0100

    -Wwrite-strings: Constify shell_escape and plug make_command leak
    
    gdb/ChangeLog:
    2017-04-05  Pedro Alves	 <palves@redhat.com>
    
    	* cli/cli-cmds.c (shell_escape): Constify 'arg' parameter.
    	(shell_command): New function.
    	(make_command): Use std::string.
    	(init_cli_cmds): Register shell_command instead of shell_escape.

Diff:
---
 gdb/ChangeLog      |  7 +++++++
 gdb/cli/cli-cmds.c | 26 +++++++++++++++-----------
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 925cb94..00f8d1c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2017-04-05  Pedro Alves	 <palves@redhat.com>
+
+	* cli/cli-cmds.c (shell_escape): Constify 'arg' parameter.
+	(shell_command): New function.
+	(make_command): Use std::string.
+	(init_cli_cmds): Register shell_command instead of shell_escape.
+
 2017-04-05  Pedro Alves  <palves@redhat.com>
 
 	* breakpoint.c (dprintf_function, dprintf_channel): Don't initialize.
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index b5c9d0b..f7ffb6d 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -82,7 +82,7 @@ static void show_user (char *, int);
 
 static void make_command (char *, int);
 
-static void shell_escape (char *, int);
+static void shell_escape (const char *, int);
 
 static void edit_command (char *, int);
 
@@ -735,7 +735,7 @@ echo_command (char *text, int from_tty)
 }
 
 static void
-shell_escape (char *arg, int from_tty)
+shell_escape (const char *arg, int from_tty)
 {
 #if defined(CANT_FORK) || \
       (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
@@ -795,6 +795,14 @@ shell_escape (char *arg, int from_tty)
 #endif /* Can fork.  */
 }
 
+/* Implementation of the "shell" command.  */
+
+static void
+shell_command (char *arg, int from_tty)
+{
+  shell_escape (arg, from_tty);
+}
+
 static void
 edit_command (char *arg, int from_tty)
 {
@@ -1306,18 +1314,14 @@ disassemble_command (char *arg, int from_tty)
 static void
 make_command (char *arg, int from_tty)
 {
-  char *p;
-
   if (arg == 0)
-    p = "make";
+    shell_escape ("make", from_tty);
   else
     {
-      p = (char *) xmalloc (sizeof ("make ") + strlen (arg));
-      strcpy (p, "make ");
-      strcpy (p + sizeof ("make ") - 1, arg);
-    }
+      std::string cmd = std::string ("make ") + arg;
 
-  shell_escape (p, from_tty);
+      shell_escape (cmd.c_str (), from_tty);
+    }
 }
 
 static void
@@ -1881,7 +1885,7 @@ from the target."),
 		  _("Generic command for showing gdb debugging flags"),
 		  &showdebuglist, "show debug ", 0, &showlist);
 
-  c = add_com ("shell", class_support, shell_escape, _("\
+  c = add_com ("shell", class_support, shell_command, _("\
 Execute the rest of the line as a shell command.\n\
 With no arguments, run an inferior shell."));
   set_cmd_completer (c, filename_completer);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]