gdb: Use string_printf to format int fields instead of a fixed size buffer
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 20 Nov 2018 13:36:49 +0000 (13:36 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 20 Nov 2018 23:01:42 +0000 (23:01 +0000)
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
gdb/cli-out.c

index 66fe9c9f28f49a2b4e61f579bfb04624b2b26ce6..ddd93f246b6a0d681a1a534d58b44c0258ba5d8c 100644 (file)
@@ -1,3 +1,8 @@
+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,
index 9ffd6f01577548041739653032ee511d202e867d..7e3ee3e54c1a6bf6cce7c2f4fd783f142b8bcc71 100644 (file)
@@ -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 */
This page took 0.030354 seconds and 4 git commands to generate.