[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: Bernhard Voelker
Subject: Re: [PATCH] parse_long_options: after --help, avoid fallthrough into --version
Date: Thu, 17 Jul 2014 09:13:56 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 07/17/2014 03:00 AM, Jim Meyering wrote:
> On Wed, Jul 16, 2014 at 3:43 PM, Bernhard Voelker
> <address@hidden> wrote:
>>          case 'h':
>>            (*usage_func) (EXIT_SUCCESS);
>> +          exit (EXIT_SUCCESS);
> Does that elicit a dead-code warning, when some static analysis
> tool notices the statement after an always-"noreturn" function call?

Good point.
Unfortunately, it's not possible to run the online coverity analysis
too often, so I went with the following ...

> What do you think about adding the noreturn attribute to the
> declaration of the usage_func parameter?

I added "_Noreturn" like this:

diff --git a/lib/long-options.c b/lib/long-options.c
index fa7d1cd..0af7c0d 100644
--- a/lib/long-options.c
+++ b/lib/long-options.c
@@ -46,7 +46,7 @@ parse_long_options (int argc,
                     const char *command_name,
                     const char *package,
                     const char *version,
-                    void (*usage_func) (int),
+                    _Noreturn void (*usage_func) (int),
                     /* const char *author1, ...*/ ...)
   int c;
diff --git a/lib/long-options.h b/lib/long-options.h
index a44ae2e..18ad6d6 100644
--- a/lib/long-options.h
+++ b/lib/long-options.h
@@ -22,5 +22,5 @@ void parse_long_options (int _argc,
                          const char *_command_name,
                          const char *_package,
                          const char *_version,
-                         void (*_usage) (int),
+                         _Noreturn void (*_usage) (int),
                          /* const char *author1, ...*/ ...);

but coverity seems to ignore it, and still complains about
the fall-through.
So I wonder if I shall go another loop with the initial exit()
approach to see if there's a dead-code warning then.
(Due to restrictions of the free coverity scan I have to wait
another 24 hours for the next run.)

Thank you both & have a nice day,

reply via email to

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