From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 107858 invoked by alias); 4 Apr 2017 17:26:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 107514 invoked by uid 89); 4 Apr 2017 17:26:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Apr 2017 17:26:00 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51ECCC04B92E for ; Tue, 4 Apr 2017 17:26:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51ECCC04B92E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 51ECCC04B92E Received: from cascais.lan (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7272218247 for ; Tue, 4 Apr 2017 17:25:59 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 04/18] -Wwrite-strings: Constify shell_escape and plug make_command leak Date: Tue, 04 Apr 2017 17:26:00 -0000 Message-Id: <1491326751-16180-5-git-send-email-palves@redhat.com> In-Reply-To: <1491326751-16180-1-git-send-email-palves@redhat.com> References: <1491326751-16180-1-git-send-email-palves@redhat.com> X-SW-Source: 2017-04/txt/msg00039.txt.bz2 gdb/ChangeLog: yyyy-mm-dd Pedro Alves * 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. --- gdb/cli/cli-cmds.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) 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); -- 2.5.5