From patchwork Tue Jan 16 19:46:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 25421 Received: (qmail 44037 invoked by alias); 16 Jan 2018 19:46:50 -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 44027 invoked by uid 89); 16 Jan 2018 19:46:49 -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, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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, 16 Jan 2018 19:46:48 +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 16A9C34CD; Tue, 16 Jan 2018 19:46:47 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id E12B7608F5; Tue, 16 Jan 2018 19:46:43 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Eli Zaretskii , Sergio Durigan Junior Subject: [PATCH] Fix warning on gdb/compile/compile.c (C++-ify "triplet_rx") Date: Tue, 16 Jan 2018 14:46:41 -0500 Message-Id: <20180116194641.22361-1-sergiodj@redhat.com> In-Reply-To: <87po69zkxe.fsf@redhat.com> References: <87po69zkxe.fsf@redhat.com> X-IsSubscribed: yes 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)"). 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-16 Sergio Durigan Junior * compile/compile.c (compile_to_object): Convert "triplet_rx" to "std::string". --- gdb/compile/compile.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 2ee75930ac..47646169c8 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -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) @@ -527,15 +527,15 @@ compile_to_object (struct command_line *cmd, const char *cmd_string, } else { - const char *os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch)); - const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); + std::string os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch)); + std::string 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 = 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) {