[patch] Re: [commit] Re: [PATCH] Avoid potencially-stale errno usage

Jan Kratochvil
2013-04-11T06:38:22Z

On Tue, 09 Apr 2013 14:19:42 +0200, Pedro Alves wrote:
> +static void
> +unpush_and_perror (const char *string)
> +{
> + char *errstr;
> +
> + errstr = xstrprintf ("%s: %s", string, safe_strerror (errno));
> + make_cleanup (xfree, errstr);
> +
> + remote_unpush_target ();
> + throw_error (TARGET_CLOSE_ERROR, "%s", errstr);
> +}

It has changed the output message:

20130409Build-gdbcvs-dwarf41-gcchead-f19/fedora-19-x86_64/out/gdb-m32.log:Remote communication error. Target disconnected.: Connection reset by peer.
20130410Build-gdbcvs-dwarf41-gcchead-f19/fedora-19-x86_64/out/gdb-m64.log:Remote communication error. Target disconnected.: Connection reset by peer

Formerly:

throw_perror_with_name (enum errors errcode, const char *string)
{
[...]
throw_error (errcode, _("%s."), combined);
}

Instead of changing the testsuite expectation in
2a9030220efff2f7e5e7447ee523726bd9585072 I find better to retain the backward
compatibility, although it is sure a nitpick.

Also I have simplified the code a bit.

Thanks,
Jan

gdb/
2013-04-11 Jan Kratochvil <jan.kratochvil@redhat.com>

* remote.c (unpush_and_perror): Add output message final dot.

diff --git a/gdb/remote.c b/gdb/remote.c
index de075c8..f0dbba6 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7036,18 +7036,17 @@ remote_files_info (struct target_ops *ignore)
/* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
error to higher layers. Called when a serial error is detected.
The exception message is STRING, followed by a colon and a blank,
- then the system error message for errno at function entry. */
+ the system error message for errno at function entry and final dot
+ for output compatibility with throw_perror_with_name. */

static void
unpush_and_perror (const char *string)
{
- char *errstr;
-
- errstr = xstrprintf ("%s: %s", string, safe_strerror (errno));
- make_cleanup (xfree, errstr);
+ int saved_errno = errno;

remote_unpush_target ();
- throw_error (TARGET_CLOSE_ERROR, "%s", errstr);
+ throw_error (TARGET_CLOSE_ERROR, "%s: %s.", string,
+ safe_strerror (saved_errno));
}

/* Read a single character from the remote end. */