[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] parse_long_options: after --help, avoid fallthrough into --v

From: Eric Blake
Subject: Re: [PATCH] parse_long_options: after --help, avoid fallthrough into --version
Date: Wed, 16 Jul 2014 16:56:30 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 07/16/2014 04:43 PM, Bernhard Voelker wrote:
> Does anyone know of a tool using parse_long_options() which
> would rely on printing the --version text right after the usage
> text for the --help option?

I'm guessing that the (*usage) callback is SUPPOSED to be marked with
the noreturn attribute.  If anything, this is a sign that we are either
missing annotations, or that Coverity doesn't know how to properly use
the noreturn annotation.  But I can't guarantee that all clients of this
module actually mark their usage callback noreturn.

> +++ b/lib/long-options.c
> @@ -64,13 +64,14 @@ parse_long_options (int argc,
>          {
>          case 'h':
>            (*usage_func) (EXIT_SUCCESS);
> +          exit (EXIT_SUCCESS);

This feels slightly wrong.  The _reason_ that usage_func is supposed to
be noreturn is so that if it encounters a write failure while printing
usage text, it can guarantee non-zero exit status.  But this code
blindly tries to exit with 0 status,  if the caller hasn't installed
atexit(close_stdout).  That said,...

>          case 'v':
>            {
>              va_list authors;
>              va_start (authors, usage_func);
>              version_etc_va (stdout, command_name, package, version, authors);
> -            exit (0);
> +            exit (EXIT_SUCCESS);

...it's no worse than this one, which also fails to guarantee non-zero
status on failure to write to stdout.

So I guess I'm okay with the patch.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]