From: Mark Wielaard <mark@klomp.org>
To: Colin Cross <ccross@google.com>, elfutils-devel@sourceware.org
Subject: Re: [PATCH] lib: Fix unused parameter warning in lib/error.c
Date: Thu, 09 Sep 2021 12:09:39 +0200 [thread overview]
Message-ID: <6098de6222cc54410231586581d08cf442e00f56.camel@klomp.org> (raw)
In-Reply-To: <20210908182109.2150134-1-ccross@google.com>
Hi Colin
(CC Saleem who introduced this new error replacement function),
On Wed, 2021-09-08 at 11:21 -0700, Colin Cross via Elfutils-devel
wrote:
> Mark the errnum parameter with __attribute__((unused)).
Thanks, that is interesting.
But I think this is an actual bug in the code.
Rereviewing the new replacement error function:
> #if !defined(HAVE_ERROR_H) && defined(HAVE_ERR_H)
> #include <stdarg.h>
> #include <stdlib.h>
> #include <err.h>
>
> unsigned int error_message_count = 0;
>
> void error(int status, int errnum, const char *format, ...) {
> va_list argp;
>
> va_start(argp, format);
> verr(status, format, argp);
> va_end(argp);
>
> if (status)
> exit(status);
> ++error_message_count;
> }
> #endif
I see three issues with the code:
1) error is supposed to first flush stdout before printing to stderr.
This is minor, but might make the error message appear differently
when stdout and stderr are mixed.
2) errnum isn't actually used as you noticed.
error is supposed to print strerror(errnum) if errnum is not zero.
Instead verr print strerror(errno), even when errno is zero.
So I think the code should use errnum (if it is not zero), save the
current value of errno, assign errnum to errno, call verr and set
errno back.
3) error ignores status if it is zero, but verr seems to call exit (0)
meaning it terminates the program instead of simply printing an
error and increasing error_message_count.
Could the error replacement function be rewritten to behave more
correctly?
Thanks,
Mark
next prev parent reply other threads:[~2021-09-09 10:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-08 18:21 Colin Cross
2021-09-09 10:09 ` Mark Wielaard [this message]
2021-09-10 18:07 ` [PATCH] lib: Make error.c more like error(3) Colin Cross
2021-09-12 21:00 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6098de6222cc54410231586581d08cf442e00f56.camel@klomp.org \
--to=mark@klomp.org \
--cc=ccross@google.com \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).