From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
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:00 -0000 [thread overview]
Message-ID: <81914f01b8c70c20744c2960c4a71136bcb6e913.1542745482.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1542745482.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1542745482.git.andrew.burgess@embecosm.com>
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 */
--
2.14.5
next prev parent reply other threads:[~2018-11-20 20:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-20 20:30 [PATCH 0/2] Changes to cli-out.c for field alignment and formatting Andrew Burgess
2018-11-20 20:30 ` [PATCH 1/2] gdb: Respect field width and alignment for 'fmt' fields in CLI output Andrew Burgess
2018-11-20 22:17 ` Tom Tromey
2018-11-20 20:30 ` Andrew Burgess [this message]
2018-11-20 22:18 ` [PATCH 2/2] gdb: Use string_printf to format int fields instead of a fixed size buffer Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81914f01b8c70c20744c2960c4a71136bcb6e913.1542745482.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox