This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] gdb: Use string_printf to format int fields instead of a fixed size buffer
- From: Andrew Burgess <aburgess at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 20 Nov 2018 23:05:01 -0000
- Subject: [binutils-gdb] gdb: Use string_printf to format int fields instead of a fixed size buffer
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d63095c426f704f75d943a7481189628403ed58f
commit d63095c426f704f75d943a7481189628403ed58f
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date: Tue Nov 20 13:36:49 2018 +0000
gdb: Use string_printf to format int fields instead of a fixed size buffer
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.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/cli-out.c | 6 ++----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 66fe9c9..ddd93f2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2018-11-20 Andrew Burgess <andrew.burgess@embecosm.com>
+ * cli-out.c (cli_ui_out::do_field_int): Use string_printf rather
+ than a fixed size buffer.
+
+2018-11-20 Andrew Burgess <andrew.burgess@embecosm.com>
+
* breakpoint.c (print_one_breakpoint_location): Reduce whitespace,
and remove insertion of extra spaces in GDB's output.
* cli-out.c (cli_ui_out::do_field_fmt): Update header comment.
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 9ffd6f0..7e3ee3e 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 */