[review] Simplify print_sys_errmsg
Commit Message
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/479
......................................................................
Simplify print_sys_errmsg
On irc, Christian pointed out that print_sys_errmsg could be
simplified by avoiding alloca entirely. This patch implements this.
gdb/ChangeLog
2019-10-31 Tom Tromey <tromey@adacore.com>
* utils.c (print_sys_errmsg): Simplify.
Change-Id: I5e9a042d957d44d8d76477729da33feb6f11ec37
---
M gdb/ChangeLog
M gdb/utils.c
2 files changed, 5 insertions(+), 6 deletions(-)
Comments
Christian Biesinger has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/479
......................................................................
Patch Set 1: Code-Review+1
Looks great to me!
Tom Tromey has abandoned this change. ( https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/479 )
Change subject: Simplify print_sys_errmsg
......................................................................
Abandoned
I pushed this but somehow the change-id changed so gerrit did not notice.
@@ -1,5 +1,9 @@
2019-10-31 Tom Tromey <tromey@adacore.com>
+ * utils.c (print_sys_errmsg): Simplify.
+
+2019-10-31 Tom Tromey <tromey@adacore.com>
+
* gdbsupport/mingw-strerror.c (safe_strerror): Constify result.
* gdbsupport/gdb-dlfcn.c (gdb_dlopen): Update.
@@ -629,15 +629,10 @@
print_sys_errmsg (const char *string, int errcode)
{
const char *err = safe_strerror (errcode);
- char *combined = (char *) alloca (strlen (err) + strlen (string) + 3);
- strcpy (combined, string);
- strcat (combined, ": ");
- strcat (combined, err);
-
/* We want anything which was printed on stdout to come out first, before
this message. */
gdb_flush (gdb_stdout);
- fprintf_unfiltered (gdb_stderr, "%s.\n", combined);
+ fprintf_unfiltered (gdb_stderr, "%s: %s.\n", string, err);
}
/* Control C eventually causes this to be called, at a convenient time. */