diff options
author | Andrew Cagney <cagney@redhat.com> | 2004-06-29 14:57:39 +0000 |
---|---|---|
committer | Andrew Cagney <cagney@redhat.com> | 2004-06-29 14:57:39 +0000 |
commit | e623b5041fed796282b4dd432e59fcab026136ca (patch) | |
tree | e16ee3bd0fc75d3148a8b683137ee7ccd4a04970 /gdb/utils.c | |
parent | 3874ed78d9c5c18fc0f4b2f9bd76f4f0232d691e (diff) | |
download | gdb-e623b5041fed796282b4dd432e59fcab026136ca.zip gdb-e623b5041fed796282b4dd432e59fcab026136ca.tar.gz gdb-e623b5041fed796282b4dd432e59fcab026136ca.tar.bz2 |
2004-06-28 Andrew Cagney <cagney@gnu.org>
* defs.h (xstrvprintf): Declare.
* utils.c (xstrvprintf): New function.
(internal_vproblem, xstrprintf, xasprintf)
(vfprintf_maybe_filtered, vfprintf_unfiltered): Use xstrvprintf.
* serial.c (serial_printf): Ditto.
* complaints.c (vcomplaint): Ditto.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index f1c2fe4..409e0bc 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -752,7 +752,7 @@ internal_vproblem (struct internal_problem *problem, so that the user knows that they are living on the edge. */ { char *msg; - xvasprintf (&msg, fmt, ap); + msg = xstrvprintf (fmt, ap); reason = xstrprintf ("\ %s:%d: %s: %s\n\ A problem internal to GDB has been detected,\n\ @@ -1156,7 +1156,7 @@ xstrprintf (const char *format, ...) char *ret; va_list args; va_start (args, format); - xvasprintf (&ret, format, args); + ret = xstrvprintf (format, args); va_end (args); return ret; } @@ -1166,7 +1166,7 @@ xasprintf (char **ret, const char *format, ...) { va_list args; va_start (args, format); - xvasprintf (ret, format, args); + (*ret) = xstrvprintf (format, args); va_end (args); } @@ -1186,6 +1186,21 @@ xvasprintf (char **ret, const char *format, va_list ap) "vasprintf call failed (errno %d)", errno); } +char * +xstrvprintf (const char *format, va_list ap) +{ + char *ret = NULL; + int status = vasprintf (&ret, format, ap); + /* NULL is returned when there was a memory allocation problem. */ + if (ret == NULL) + nomem (0); + /* A negative status (the printed length) with a non-NULL buffer + should never happen, but just to be sure. */ + if (status < 0) + internal_error (__FILE__, __LINE__, + "vasprintf call failed (errno %d)", errno); + return ret; +} /* My replacement for the read system call. Used like `read' but keeps going if `read' returns too soon. */ @@ -2260,7 +2275,7 @@ vfprintf_maybe_filtered (struct ui_file *stream, const char *format, char *linebuffer; struct cleanup *old_cleanups; - xvasprintf (&linebuffer, format, args); + linebuffer = xstrvprintf (format, args); old_cleanups = make_cleanup (xfree, linebuffer); fputs_maybe_filtered (linebuffer, stream, filter); do_cleanups (old_cleanups); @@ -2279,7 +2294,7 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args) char *linebuffer; struct cleanup *old_cleanups; - xvasprintf (&linebuffer, format, args); + linebuffer = xstrvprintf (format, args); old_cleanups = make_cleanup (xfree, linebuffer); fputs_unfiltered (linebuffer, stream); do_cleanups (old_cleanups); |