ada_print_floating: Remove use of statically sized buffer.
authorJoel Brobecker <brobecker@adacore.com>
Thu, 19 Dec 2013 16:19:45 +0000 (20:19 +0400)
committerJoel Brobecker <brobecker@adacore.com>
Tue, 7 Jan 2014 04:17:40 +0000 (08:17 +0400)
ada_print_floating declares a char buffer with a size that we're hoping
to always be large enough to hold any string representation of a float
value.  But that's not really necessary, and also forces us to create
a small wrapper (ui_memcpy) to perform the extraction from a temporary
stream into this buffer.  This patches fixes both issues by relying on
ui_file_xstrdup.  This forces us to make a few adjustments that are
minor in nature, as we now need to defer the cleanup to the end of
the function.

gdb/ChangeLog:

        * ada-valprint.c (ui_memcpy): Delete.
        (ada_print_floating): Update documentation.  Add empty line
        between between function documentation and implementation.
        Delete variable "buffer".  Use ui_file_xstrdup in place of
        ui_file_put.  Minor adjustments following this change.

gdb/ChangeLog
gdb/ada-valprint.c

index e66861774e5b70587998dc67140690723000c7fa..9fc947b578383635ba1789fac96521dba30c87a3 100644 (file)
@@ -1,3 +1,11 @@
+2014-01-07  Joel Brobecker  <brobecker@adacore.com>
+
+       * ada-valprint.c (ui_memcpy): Delete.
+       (ada_print_floating): Update documentation.  Add empty line
+       between between function documentation and implementation.
+       Delete variable "buffer".  Use ui_file_xstrdup in place of
+       ui_file_put.  Minor adjustments following this change.
+
 2014-01-07  Joel Brobecker  <brobecker@adacore.com>
 
        * ada-valprint.c (ada_val_print_string): New function,
index d1c855324ecab01beaf86b8580a3d6029c4f3f93..1ae2089a08fb627099e2f0494d8475344ba7b011 100644 (file)
@@ -289,32 +289,22 @@ char_at (const gdb_byte *string, int i, int type_len,
                                            type_len, byte_order);
 }
 
-/* Wrapper around memcpy to make it legal argument to ui_file_put.  */
-static void
-ui_memcpy (void *dest, const char *buffer, long len)
-{
-  memcpy (dest, buffer, (size_t) len);
-  ((char *) dest)[len] = '\0';
-}
-
 /* Print a floating-point value of type TYPE, pointed to in GDB by
    VALADDR, on STREAM.  Use Ada formatting conventions: there must be
    a decimal point, and at least one digit before and after the
-   point.  We use GNAT format for NaNs and infinities.  */
+   point.  We use the GNAT format for NaNs and infinities.  */
+
 static void
 ada_print_floating (const gdb_byte *valaddr, struct type *type,
                    struct ui_file *stream)
 {
-  char buffer[64];
   char *s, *result;
   struct ui_file *tmp_stream = mem_fileopen ();
   struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
 
   print_floating (valaddr, type, tmp_stream);
-  ui_file_put (tmp_stream, ui_memcpy, buffer);
-  do_cleanups (cleanups);
-
-  result = buffer;
+  result = ui_file_xstrdup (tmp_stream, NULL);
+  make_cleanup (xfree, result);
 
   /* Modify for Ada rules.  */
 
@@ -348,9 +338,11 @@ ada_print_floating (const gdb_byte *valaddr, struct type *type,
        fprintf_filtered (stream, "%s.0", result);
       else
        fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
-      return;
     }
-  fprintf_filtered (stream, "%s", result);
+  else
+    fprintf_filtered (stream, "%s", result);
+
+  do_cleanups (cleanups);
 }
 
 void
This page took 0.026501 seconds and 4 git commands to generate.