From patchwork Wed Apr 5 18:22:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 19872 Received: (qmail 70682 invoked by alias); 5 Apr 2017 18:23:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 70652 invoked by uid 89); 5 Apr 2017 18:23:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, 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; Wed, 05 Apr 2017 18:22:59 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7851C04BD48 for ; Wed, 5 Apr 2017 18:22:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E7851C04BD48 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 E7851C04BD48 Received: from cascais.lan (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BFFF18997 for ; Wed, 5 Apr 2017 18:22:57 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] -Wwrite-strings: Fix Solaris "set procfs-file" Date: Wed, 5 Apr 2017 19:22:56 +0100 Message-Id: <1491416576-9775-1-git-send-email-palves@redhat.com> Compiling GDB with -Wwrite-strings flags this code in gdb/proc-api.c: static char *procfs_filename = "procfs_trace"; as needing a cast. However, this variable is a command variable, and as such it's incorrect to initialize it to a literal, since when you use the corresponding set command, gdb frees the old string... I didn't manage to fully build Solaris gdb (fails for other reasons), but I confirmed that the system GDB on Solaris 11 crashes when running this command: (gdb) set procfs-file foo Segmentation Fault (core dumped) So I don't think this commit can make it worse than the status quo. gdb/ChangeLog: 2017-04-05 Pedro Alves * proc-api.c (procfs_filename): Don't initialize procfs_filename. (prepare_to_trace): Assume procfs_filename is non-NULL. (_initialize_proc_api): Give procfs_filename a default value here. --- gdb/ChangeLog | 7 +++++++ gdb/proc-api.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d391859..f4e9562 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2017-04-05 Pedro Alves + * proc-api.c (procfs_filename): Don't initialize + procfs_filename. + (prepare_to_trace): Assume procfs_filename is non-NULL. + (_initialize_proc_api): Give procfs_filename a default value here. + +2017-04-05 Pedro Alves + * break-catch-throw.c (handle_gnu_v3_exceptions): Constify 'cond_string' parameter. (extract_exception_regexp): Constify 'string' parameter. diff --git a/gdb/proc-api.c b/gdb/proc-api.c index 72746ce..dbadd55 100644 --- a/gdb/proc-api.c +++ b/gdb/proc-api.c @@ -60,15 +60,14 @@ struct trans { static int procfs_trace = 0; static FILE *procfs_file = NULL; -static char *procfs_filename = "procfs_trace"; +static char *procfs_filename; static void prepare_to_trace (void) { if (procfs_trace) /* if procfs tracing turned on */ if (procfs_file == NULL) /* if output file not yet open */ - if (procfs_filename != NULL) /* if output filename known */ - procfs_file = fopen (procfs_filename, "a"); /* open output file */ + procfs_file = fopen (procfs_filename, "a"); /* open output file */ } static void @@ -785,6 +784,7 @@ Show tracing for /proc api calls."), NULL, NULL, /* FIXME: i18n: */ &setlist, &showlist); + procfs_filename = xstrdup ("procfs_trace"); add_setshow_filename_cmd ("procfs-file", no_class, &procfs_filename, _("\ Set filename for /proc tracefile."), _("\ Show filename for /proc tracefile."), NULL,