From 2238eb820f751309161ec55d2ba763e0e1531846 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Wed, 24 Nov 2021 06:19:33 +0100 Subject: [PATCH] zdump/zg: Save errno in _zg_err_errno() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _zg_err_errno() should save the current errno value before calling any libc functions because they could change it. Failing to do so, may result in _zg_err_errno() displaying an incorrect error message. Signed-off-by: Alexander Egorenkov Reviewed-by: Marc Hartmayer Signed-off-by: Jan Höppner --- zdump/zg_error.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zdump/zg_error.c b/zdump/zg_error.c index 99cbd611..f5ecc0a5 100644 --- a/zdump/zg_error.c +++ b/zdump/zg_error.c @@ -19,10 +19,12 @@ static inline void _zg_err(const char *fmt, va_list ap) static inline void _zg_err_errno(const char *fmt, va_list ap) { + const int errno_backup = errno; + fflush(stdout); fprintf(stderr, "%s: ", "zgetdump"); vfprintf(stderr, fmt, ap); - fprintf(stderr, " (%s)", strerror(errno)); + fprintf(stderr, " (%s)", strerror(errno_backup)); fprintf(stderr, "\n"); }