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.
{
/* 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
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;