From patchwork Tue Nov 20 20:30:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 30224 Received: (qmail 11238 invoked by alias); 20 Nov 2018 20:30:51 -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 10801 invoked by uid 89); 20 Nov 2018 20:30:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 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= X-HELO: mail-wm1-f67.google.com Received: from mail-wm1-f67.google.com (HELO mail-wm1-f67.google.com) (209.85.128.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Nov 2018 20:30:25 +0000 Received: by mail-wm1-f67.google.com with SMTP id q26so3571057wmf.5 for ; Tue, 20 Nov 2018 12:30:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=BWqW8ixydIrybrSOToa7cTVrIH9mpPpQVzkRs/6NviM=; b=ZhZTkhcsslGTzuIxI7eag9A5e8d3gIoJtvqXfVTnyDJk9SOwPfQelbatMFRWEsWc/a m5mF2bdPgGr77w/8XcHRhu+ocPUPGl5rPrgliqqjGnmbS0nwWlWgi1YDUveP4d1FKZXW LCk+C+X0ZnO/qY4Rs9k+NRp0sZBiiYXo/Vh5Mpfjxuc0W7XWw2IRf4/R1Zg0ofrOr061 ml3BKJYfqLIxizziiTZ1xOUlMOU07adp4G+bw3IDS64D7ZbTjYpighbBCFmDG2q8Zp4f GHxd8BIPKClywJPvkqiWWzhqWH+WuY+EvIaNMz0+yaCqP/LFfMnoSxA3YswRVUHddgXm /VaA== Return-Path: Received: from localhost (host81-156-111-139.range81-156.btcentralplus.com. [81.156.111.139]) by smtp.gmail.com with ESMTPSA id b18sm14551877wrw.83.2018.11.20.12.30.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Nov 2018 12:30:14 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/2] gdb: Use string_printf to format int fields instead of a fixed size buffer Date: Tue, 20 Nov 2018 20:30:06 +0000 Message-Id: <81914f01b8c70c20744c2960c4a71136bcb6e913.1542745482.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes This patch removes a FIXME comment from cli-out.c, now instead of formatting integers into a fixed size buffer we build a std::string and extract the formatted integer from that. The old code using a fixed size buffer was probably fine (the integer was not going to overflow it) and probably slightly more efficient (avoids building a std::string) however, given we already have utility code in GDB that will allow the 'FIXME' comment to be removed, it seems like an easy improvement. gdb/ChangeLog: * cli-out.c (cli_ui_out::do_field_int): Use string_printf rather than a fixed size buffer. --- gdb/ChangeLog | 5 +++++ gdb/cli-out.c | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gdb/cli-out.c b/gdb/cli-out.c index 3fe131fef37..57687cd663f 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -94,14 +94,12 @@ void cli_ui_out::do_field_int (int fldno, int width, ui_align alignment, const char *fldname, int value) { - char buffer[20]; /* FIXME: how many chars long a %d can become? */ - if (m_suppress_output) return; - xsnprintf (buffer, sizeof (buffer), "%d", value); + std::string str = string_printf ("%d", value); - do_field_string (fldno, width, alignment, fldname, buffer); + do_field_string (fldno, width, alignment, fldname, str.c_str ()); } /* used to omit a field */