bug-gnulib
[Top][All Lists]
Advanced

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

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


From: Bernhard Voelker
Subject: [PATCH] parse_long_options: after --help, avoid fallthrough into --version
Date: Thu, 17 Jul 2014 00:43:02 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

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?

Otherwise ... see patch below.

Have a nice day,
Berny

>From f75f6dd2671231c880ee9cf040ccebaf7c58b6c0 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Thu, 17 Jul 2014 00:30:28 +0200
Subject: [PATCH] parse_long_options: after --help, avoid fallthrough into
 --version

* lib/long-options.c (parse_long_options): Add exit() with
EXIT_SUCCESS after invoking the given usage function - just in case
the usage_func would not exit().  Spotted by coverity.
While at it, pass EXIT_SUCCESS rather than 0 in the --version case
for clarity.
---
 ChangeLog          | 9 +++++++++
 lib/long-options.c | 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index e3d86b3..b9b0a94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-07-17  Bernhard Voelker  <address@hidden>
+
+       parse_long_options: after --help, avoid fallthrough into --version
+       * lib/long-options.c (parse_long_options): Add exit() with
+       EXIT_SUCCESS after invoking the given usage function - just in case
+       the usage_func would not exit().  Spotted by coverity.
+       While at it, pass EXIT_SUCCESS rather than 0 in the --version case
+       for clarity.
+
 2014-07-14  Daiki Ueno  <address@hidden>

        announce-gen: avoid failure when Digest::SHA is installed
diff --git a/lib/long-options.c b/lib/long-options.c
index fa7d1cd..779ae75 100644
--- a/lib/long-options.c
+++ b/lib/long-options.c
@@ -64,13 +64,14 @@ parse_long_options (int argc,
         {
         case 'h':
           (*usage_func) (EXIT_SUCCESS);
+          exit (EXIT_SUCCESS);

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

         default:
-- 
1.8.4.5




reply via email to

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