From patchwork Sat Mar 17 15:46:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26351 Received: (qmail 51098 invoked by alias); 17 Mar 2018 15:46:44 -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 50275 invoked by uid 89); 17 Mar 2018 15:46:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2424 X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.148.2) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Mar 2018 15:46:42 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 6A033C31D for ; Sat, 17 Mar 2018 10:46:41 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id xE2beqHM0E0sxxE2beotxv; Sat, 17 Mar 2018 10:46:41 -0500 Received: from 174-29-60-18.hlrn.qwest.net ([174.29.60.18]:39956 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1exE2b-000NY2-6Y; Sat, 17 Mar 2018 10:46:41 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Change auto_load_objfile_script_1 to use std::string Date: Sat, 17 Mar 2018 09:46:38 -0600 Message-Id: <20180317154638.1370-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1exE2b-000NY2-6Y X-Source-Sender: 174-29-60-18.hlrn.qwest.net (bapiya.Home) [174.29.60.18]:39956 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This replaces some manual string manipulation in auto_load_objfile_script_1 with std::string, simplifying the code and allowing the removal of some cleanups. Tested by the buildbot. gdb/ChangeLog 2018-03-17 Tom Tromey * auto-load.c (auto_load_objfile_script_1): Use std::string. --- gdb/ChangeLog | 4 ++++ gdb/auto-load.c | 26 ++++++++------------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 70bddbc862..09ecb87e13 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -769,24 +769,19 @@ static int auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, const struct extension_language_defn *language) { - char *filename, *debugfile; - int len, retval; - struct cleanup *cleanups; + const char *debugfile; + int retval; const char *suffix = ext_lang_auto_load_suffix (language); - len = strlen (realname); - filename = (char *) xmalloc (len + strlen (suffix) + 1); - memcpy (filename, realname, len); - strcpy (filename + len, suffix); + std::string filename = std::string (realname) + suffix; - cleanups = make_cleanup (xfree, filename); - - gdb_file_up input = gdb_fopen_cloexec (filename, "r"); - debugfile = filename; + gdb_file_up input = gdb_fopen_cloexec (filename.c_str (), "r"); + debugfile = filename.c_str (); if (debug_auto_load) fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file \"%s\" %s.\n"), debugfile, input ? _("exists") : _("does not exist")); + std::string debugfile_holder; if (!input) { /* Also try the same file in a subdirectory of gdb's data @@ -802,14 +797,10 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, for (const gdb::unique_xmalloc_ptr &dir : vec) { - debugfile = (char *) xmalloc (strlen (dir.get ()) - + strlen (filename) + 1); - strcpy (debugfile, dir.get ()); - /* FILENAME is absolute, so we don't need a "/" here. */ - strcat (debugfile, filename); + debugfile_holder = dir.get () + filename; + debugfile = debugfile_holder.c_str (); - make_cleanup (xfree, debugfile); input = gdb_fopen_cloexec (debugfile, "r"); if (debug_auto_load) fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file " @@ -862,7 +853,6 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname, else retval = 0; - do_cleanups (cleanups); return retval; }