Fix -Wuninitialized warnings.
[deliverable/binutils-gdb.git] / gdb / utils.c
index e3e88dffae99a1647cbb9f56484808d583c15895..46d0eb1e6f4fa6b3085df3d3f0251680a1b8e3ad 100644 (file)
@@ -407,12 +407,11 @@ null_cleanup (void *arg)
 {
 }
 
-/* Add a continuation to the continuation list, the gloabl list
+/* Add a continuation to the continuation list, the global list
    cmd_continuation. The new continuation will be added at the front.*/
 void
-add_continuation (continuation_hook, arg_list)
-     void (*continuation_hook) (struct continuation_arg *);
-     struct continuation_arg *arg_list;
+add_continuation (void (*continuation_hook) (struct continuation_arg *),
+                 struct continuation_arg *arg_list)
 {
   struct continuation *continuation_ptr;
 
@@ -472,9 +471,9 @@ discard_all_continuations (void)
 /* Add a continuation to the continuation list, the global list
    intermediate_continuation. The new continuation will be added at the front.*/
 void
-add_intermediate_continuation (continuation_hook, arg_list)
-     void (*continuation_hook) (struct continuation_arg *);
-     struct continuation_arg *arg_list;
+add_intermediate_continuation (void (*continuation_hook)
+                              (struct continuation_arg *),
+                              struct continuation_arg *arg_list)
 {
   struct continuation *continuation_ptr;
 
@@ -607,7 +606,7 @@ verror (const char *string, va_list args)
   char *err_string;
   struct cleanup *err_string_cleanup;
   /* FIXME: cagney/1999-11-10: All error calls should come here.
-     Unfortunatly some code uses the sequence: error_begin(); print
+     Unfortunately some code uses the sequence: error_begin(); print
      error message; return_to_top_level.  That code should be
      flushed. */
   error_begin ();
@@ -1080,6 +1079,35 @@ xrealloc (PTR ptr, size_t size)
 }
 \f
 
+/* Like asprintf/vasprintf but get an internal_error if the call
+   fails. */
+
+void
+xasprintf (char **ret, const char *format, ...)
+{
+  va_list args;
+  va_start (args, format);
+  xvasprintf (ret, format, args);
+  va_end (args);
+}
+
+void
+xvasprintf (char **ret, const char *format, va_list ap)
+{
+  int status = vasprintf (ret, format, ap);
+  /* NULL could be returned due to a memory allocation problem; a
+     badly format string; or something else. */
+  if ((*ret) == NULL)
+    internal_error ("%s:%d: vasprintf returned NULL buffer (errno %d)",
+                   __FILE__, __LINE__, errno);
+  /* A negative status with a non-NULL buffer shouldn't never
+     happen. But to be sure. */
+  if (status < 0)
+    internal_error ("%s:%d: vasprintf call failed (errno %d)",
+                   __FILE__, __LINE__, errno);
+}
+
+
 /* My replacement for the read system call.
    Used like `read' but keeps going if `read' returns too soon.  */
 
@@ -1351,15 +1379,10 @@ parse_escape (char **string_ptr)
    be call for printing things which are independent of the language
    of the program being debugged. */
 
-static void printchar (int c, void (*do_fputs) (const char *, struct ui_file*), void (*do_fprintf) (struct ui_file*, const char *, ...), struct ui_file *stream, int quoter);
-
 static void
-printchar (c, do_fputs, do_fprintf, stream, quoter)
-     int c;
-     void (*do_fputs) (const char *, struct ui_file *);
-     void (*do_fprintf) (struct ui_file *, const char *, ...);
-     struct ui_file *stream;
-     int quoter;
+printchar (int c, void (*do_fputs) (const char *, struct ui_file *),
+          void (*do_fprintf) (struct ui_file *, const char *, ...),
+          struct ui_file *stream, int quoter)
 {
 
   c &= 0xFF;                   /* Avoid sign bit follies */
@@ -1958,12 +1981,7 @@ vfprintf_maybe_filtered (struct ui_file *stream, const char *format,
   char *linebuffer;
   struct cleanup *old_cleanups;
 
-  vasprintf (&linebuffer, format, args);
-  if (linebuffer == NULL)
-    {
-      fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr);
-      exit (1);
-    }
+  xvasprintf (&linebuffer, format, args);
   old_cleanups = make_cleanup (free, linebuffer);
   fputs_maybe_filtered (linebuffer, stream, filter);
   do_cleanups (old_cleanups);
@@ -1982,12 +2000,7 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
   char *linebuffer;
   struct cleanup *old_cleanups;
 
-  vasprintf (&linebuffer, format, args);
-  if (linebuffer == NULL)
-    {
-      fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr);
-      exit (1);
-    }
+  xvasprintf (&linebuffer, format, args);
   old_cleanups = make_cleanup (free, linebuffer);
   fputs_unfiltered (linebuffer, stream);
   do_cleanups (old_cleanups);
@@ -2726,19 +2739,19 @@ get_cell (void)
 int
 strlen_paddr (void)
 {
-  return (TARGET_PTR_BIT / 8 * 2);
+  return (TARGET_ADDR_BIT / 8 * 2);
 }
 
 char *
 paddr (CORE_ADDR addr)
 {
-  return phex (addr, TARGET_PTR_BIT / 8);
+  return phex (addr, TARGET_ADDR_BIT / 8);
 }
 
 char *
 paddr_nz (CORE_ADDR addr)
 {
-  return phex_nz (addr, TARGET_PTR_BIT / 8);
+  return phex_nz (addr, TARGET_ADDR_BIT / 8);
 }
 
 static void
This page took 0.024327 seconds and 4 git commands to generate.