[Openswan dev] [PATCH] silent wrong uninitialized compiler warning
D. Hugh Redelmeier
hugh at mimosa.com
Fri Jun 26 16:23:42 EDT 2009
| From: Gilles Espinasse <g.esp at free.fr>
| From: "D. Hugh Redelmeier" <hugh at mimosa.com>
| To: "Gilles Espinasse" <g.esp at free.fr>; <dev at openswan.org>
| Sent: Wednesday, June 24, 2009 8:27 AM
| Subject: Re: [Openswan dev] [PATCH] silent wrong uninitialized compiler
| warning
|
|
| > | From: Gilles Espinasse <g.esp at free.fr>
| > | int nat_traversal_espinudp_socket (int sk, const char *fam, u_int32_t
| type)
| > | {
| > | - int r;
| > | + int r = 0;
| > I took a quick look at the code in 2.6.22. I don't understand its
| > complexity. It seems as if the test in the first if statement has to
| > always be true since style is initialized to auto_style. So lots of
| > the code is redundant an r is surely set before it is used.
| style is declared static.
| so there is no dead code there.
Oops! Right you are.
| > It looks as if -1 is a better value to initialize r to, if you have to
| > do so.
| >
| I don't understand the reason.
-1 means "error". Surely using the default value is an error.
And still a good idea to add a comment:
/* initializing to shut up GCC warning about uninitialized use */
| > | diff --git a/programs/pluto/rnd.c b/programs/pluto/rnd.c
| > | unsigned int max_rnd_devices = elemsof(random_devices)+1;
| > The code you are fixing here is overly complex too. While trying to
| > understand it, I found a bug: off-by-one in the for loop. The
| > definition of max_rnd_devices should not have the "+1".
| I have not written that code!
| That's true the +1 is wrong there.
| In the case all devices fail to open, openswan_log will access
| random_devices[max_rnd_devices].
Glad I got that right.
More information about the Dev
mailing list