diff mbox

[review] Simplify print_sys_errmsg

Message ID gerrit.1572562283000.I5e9a042d957d44d8d76477729da33feb6f11ec37@gnutoolchain-gerrit.osci.io
State New
Headers show

Commit Message

Simon Marchi (Code Review) Oct. 31, 2019, 10:51 p.m. UTC
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

Simon Marchi (Code Review) Oct. 31, 2019, 10:52 p.m. UTC | #1
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!
Simon Marchi (Code Review) Nov. 1, 2019, 5:54 p.m. UTC | #2
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.
diff mbox

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9f34dbc..e0bd948 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
 
diff --git a/gdb/utils.c b/gdb/utils.c
index e06eedd..f7fae35 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -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.  */