]> Savannah Git Hosting - gnulib.git/commitdiff
argp: Fix gcc -Wanalyzer-use-of-uninitialized-value warning.
authorBruno Haible <bruno@clisp.org>
Mon, 4 Sep 2023 22:22:30 +0000 (00:22 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 14 Sep 2023 10:13:39 +0000 (12:13 +0200)
* lib/argp-help.c (hol_find_entry): Access hol->entries only after
having verified that hol->num_entries > 0.

ChangeLog
lib/argp-help.c

index 86b7ee8c35a731557e2fb307e1c4e3554ea59800..9744fb0d3ed505fe46ca167b918b1286b1a5fe5e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2023-09-04  Bruno Haible  <bruno@clisp.org>
 
+       argp: Fix gcc -Wanalyzer-use-of-uninitialized-value warning.
+       * lib/argp-help.c (hol_find_entry): Access hol->entries only after
+       having verified that hol->num_entries > 0.
+
        unigbrk/uc-grapheme-breaks tests: Fix gcc -Wunused-function warning.
        * tests/unigbrk/test-uc-grapheme-breaks.c
        (graphemebreakproperty_to_string): Mark as possibly unused.
index e5baee2ca89e867000ac7ac0e7fbd8b5a14aa34b..7a277ebf13a1b4f745a91198874da70d58045b53 100644 (file)
@@ -422,8 +422,8 @@ struct hol
 {
   /* An array of hol_entry's.  */
   struct hol_entry *entries;
-  /* The number of entries in this hol.  If this field is zero, the others
-     are undefined.  */
+  /* The number of entries in this hol.  If this field is zero, entries and
+     short_options are undefined.  */
   unsigned num_entries;
 
   /* A string containing all short options in this HOL.  Each entry contains
@@ -642,21 +642,26 @@ hol_entry_first_long (const struct hol_entry *entry)
 static struct hol_entry *
 hol_find_entry (struct hol *hol, const char *name)
 {
-  struct hol_entry *entry = hol->entries;
   unsigned num_entries = hol->num_entries;
 
-  while (num_entries-- > 0)
+  if (num_entries > 0)
     {
-      const struct argp_option *opt = entry->opt;
-      unsigned num_opts = entry->num;
+      struct hol_entry *entry = hol->entries;
 
-      while (num_opts-- > 0)
-        if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0)
-          return entry;
-        else
-          opt++;
+      do
+        {
+          const struct argp_option *opt = entry->opt;
+          unsigned num_opts = entry->num;
 
-      entry++;
+          while (num_opts-- > 0)
+            if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0)
+              return entry;
+            else
+              opt++;
+
+          entry++;
+        }
+      while (--num_entries > 0);
     }
 
   return 0;