[whoops. reposting to bug-gnulib, not bug-coreutils]

Hi Sergey,

In exclude.c, we have this:

    bool
    excluded_file_name (struct exclude const *ex, char const *f)
    {
      ...
          switch (seg->type)
            {
            case exclude_pattern:
              rc = excluded_file_pattern_p (seg, f);
              break;

            case exclude_hash:
              if (!filename)
                filename = xmalloc (strlen (f) + 1);
              rc = excluded_file_name_p (seg, f, filename);
              break;
            }
          if (rc != excluded)
            {
              excluded = rc;
              break;
            }

which provokes a warning about "rc" possibly being used uninitialized.
While it appears this cannot happen in practice, it would be nice to
change the code not to evoke the warning.

If you're interested, there are several approaches:

1) add a default: abort (); in this single switch.
However, there are several others that handle only those two cases.

2) replace the switch with an if/else block: if (seg->type == exclude_pattern) 
...
and handle the other case (and "impossible" other values) via the "else" clause.

3) more invasively, but perhaps more cleanly in the long run,
we could change seg's "type" member to be boolean.


Reply via email to