From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.4]) by sourceware.org (Postfix) with ESMTPS id 37B153858414 for ; Tue, 5 Oct 2021 00:14:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 37B153858414 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway31.websitewelcome.com (Postfix) with ESMTP id CAAD243248 for ; Mon, 4 Oct 2021 19:14:56 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id XY6im5p1qgm2UXY6imuP2J; Mon, 04 Oct 2021 19:14:56 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=gGV6ofq9fsFeTsVyPhUV8YE2TGeBYWN91hfObcUW5LM=; b=fCX7KzjK1QqXtRQVMfmqIZgA48 CIQiSjkBb1ppaQ4wXrZVTdXTrlXspT17PFqC16Qyxz4ZU68P0hV84lyNXTSjVejrSanawzafzZ9t2 1Zjs1Miue/MeUfTvOBD1CRpwX; Received: from 174-16-0-219.hlrn.qwest.net ([174.16.0.219]:43158 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mXY6i-00196D-I8; Mon, 04 Oct 2021 18:14:56 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 6/6] Use std::string in print_one_catch_syscall Date: Mon, 4 Oct 2021 18:14:53 -0600 Message-Id: <20211005001453.2957929-7-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211005001453.2957929-1-tom@tromey.com> References: <20211005001453.2957929-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.0.219 X-Source-L: No X-Exim-ID: 1mXY6i-00196D-I8 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-0-219.hlrn.qwest.net (localhost.localdomain) [174.16.0.219]:43158 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Oct 2021 00:14:58 -0000 This changes print_one_catch_syscall to use std::string, removing a bit of manual memory management. --- gdb/break-catch-syscall.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index 32736f024ad..3d3b275c31e 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -250,28 +250,24 @@ print_one_catch_syscall (struct breakpoint *b, if (!c->syscalls_to_be_caught.empty ()) { - char *text = xstrprintf ("%s", ""); + std::string text; + bool first = true; for (int iter : c->syscalls_to_be_caught) { - char *previous_text = text; struct syscall s; get_syscall_by_number (gdbarch, iter, &s); + if (!first) + text += ", "; + first = false; + if (s.name != NULL) - text = xstrprintf ("%s%s, ", text, s.name); + text += s.name; else - text = xstrprintf ("%s%d, ", text, iter); - - /* We have to xfree previous_text because xstrprintf dynamically - allocates new space for text on every call. */ - xfree (previous_text); + text += std::to_string (iter); } - /* Remove the last comma. */ - text[strlen (text) - 2] = '\0'; - uiout->field_string ("what", text); - /* xfree last text. */ - xfree (text); + uiout->field_string ("what", text.c_str ()); } else uiout->field_string ("what", "", metadata_style.style ()); -- 2.31.1