From patchwork Tue Aug 29 19:25:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22409 Received: (qmail 85309 invoked by alias); 29 Aug 2017 19:25:45 -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 85242 invoked by uid 89); 29 Aug 2017 19:25:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=colon, taste, Doing X-HELO: gproxy2-pub.mail.unifiedlayer.com Received: from gproxy2-pub.mail.unifiedlayer.com (HELO gproxy2-pub.mail.unifiedlayer.com) (69.89.18.3) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Aug 2017 19:25:34 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy2.mail.unifiedlayer.com (Postfix) with ESMTP id 44E7A1E0907 for ; Tue, 29 Aug 2017 13:25:33 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 37RW1w00E2f2jeq017RZy7; Tue, 29 Aug 2017 13:25:33 -0600 X-Authority-Analysis: v=2.2 cv=F98nTupN c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=wK7MjEPj3Wv8LAWmvkIA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:36914 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dmm8g-004DCm-1b; Tue, 29 Aug 2017 13:25:30 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 08/10] Return std::string from perror_string Date: Tue, 29 Aug 2017 13:25:22 -0600 Message-Id: <20170829192524.29971-9-tom@tromey.com> In-Reply-To: <20170829192524.29971-1-tom@tromey.com> References: <20170829192524.29971-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dmm8g-004DCm-1b X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:36914 X-Source-Auth: tom+tromey.com X-Email-Count: 9 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes Change perror_string to return a std::string, removing a cleanup in the process. ChangeLog 2017-08-29 Tom Tromey * utils.c (perror_string): Return a std::string. (throw_perror_with_name, perror_warning_with_name): Update. --- gdb/ChangeLog | 5 +++++ gdb/utils.c | 28 +++++++--------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 34e5b3c..b301516 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-08-29 Tom Tromey + * utils.c (perror_string): Return a std::string. + (throw_perror_with_name, perror_warning_with_name): Update. + +2017-08-29 Tom Tromey + * demangle.c (demangle_command): Use std::string, unique_xmalloc_ptr. diff --git a/gdb/utils.c b/gdb/utils.c index 3ca29b7..af50cf0 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -751,23 +751,15 @@ add_internal_problem_command (struct internal_problem *problem) } /* Return a newly allocated string, containing the PREFIX followed - by the system error message for errno (separated by a colon). + by the system error message for errno (separated by a colon). */ - The result must be deallocated after use. */ - -static char * +static std::string perror_string (const char *prefix) { char *err; - char *combined; err = safe_strerror (errno); - combined = (char *) xmalloc (strlen (err) + strlen (prefix) + 3); - strcpy (combined, prefix); - strcat (combined, ": "); - strcat (combined, err); - - return combined; + return std::string (prefix) + ": " + err; } /* Print the system error message for errno, and also mention STRING @@ -777,10 +769,7 @@ perror_string (const char *prefix) void throw_perror_with_name (enum errors errcode, const char *string) { - char *combined; - - combined = perror_string (string); - make_cleanup (xfree, combined); + std::string combined = perror_string (string); /* I understand setting these is a matter of taste. Still, some people may clear errno but not know about bfd_error. Doing this here is not @@ -788,7 +777,7 @@ throw_perror_with_name (enum errors errcode, const char *string) bfd_set_error (bfd_error_no_error); errno = 0; - throw_error (errcode, _("%s."), combined); + throw_error (errcode, _("%s."), combined.c_str ()); } /* See throw_perror_with_name, ERRCODE defaults here to GENERIC_ERROR. */ @@ -805,11 +794,8 @@ perror_with_name (const char *string) void perror_warning_with_name (const char *string) { - char *combined; - - combined = perror_string (string); - warning (_("%s"), combined); - xfree (combined); + std::string combined = perror_string (string); + warning (_("%s"), combined.c_str ()); } /* Print the system error message for ERRCODE, and also mention STRING