]> git.tuebingen.mpg.de Git - tfortune.git/commit - tfortune.c
com_stats(): Work around bogus gcc warning.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 18 Jun 2019 17:07:24 +0000 (19:07 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 19 Jun 2019 09:32:51 +0000 (11:32 +0200)
commit2d331c0d507cb64fa7fd449582fdc0c144cce9c4
treef7aa6134720a858ea88f67c47f3a62e74880252a
parent278b70e25a37bae191066c4e08f96fd8624f31e4
com_stats(): Work around bogus gcc warning.

For some versions of gcc (7.4.0, 8.3.0, and 8.3.0-7 as shipped with
Debian-11, but not gcc-7.4.0-1ubuntu1~18.04.1), the previous patch
introduced the following warning:

tfortune.c:912:3: warning: 'lh_stats' may be used uninitialized in this function [-Wmaybe-uninitialized]
   free(lh_stats);
   ^~~~~~~~~~~~~~

We only assign to lh_stats when --verbose is given, and only free the
memory if --verbose is given.  Apparently gcc has started to believe
that the value of the "verbose" boolean variable might change, which is
impossible. Therefore, the warning is believed to be a false positive.

However, gcc has a point: There is no need to check for --verbose
twice, as a single branch is sufficient. This not only gets rid of
the warning but also makes the boolean variable pointless and removes
more lines than it adds.
tfortune.c