This commit is technically wrong. I admit that the problem will not show up on most machines.
The C standard does not require that the binary representation of a NULL pointer be 0. Initializing a struct by zeroing bytes does not guarantee that pointer fields are initialized to NULL. On the other hand, the C standard requires a static object be initialized by default in such a way that pointers are initialized to NULL. (The rule gets more intricate for unions: the first alternative is initialized.) That's why the original code was written the way it was. That's why many calls the zero() note the issue of NULL. commit fcfcde7422a4805a56a3a4a175271c56fbbbab12 Author: Andrew Cagney <[email protected]> Date: Thu Feb 11 20:05:00 2016 -0500 pluto: allocate empty "struct state" using alloc_thing() diff --git a/programs/pluto/state.c b/programs/pluto/state.c index 1b8b538..ee3884d 100644 --- a/programs/pluto/state.c +++ b/programs/pluto/state.c @@ -460,13 +460,10 @@ static struct state_hash_table statetable = { */ struct state *new_state(void) { - /* initialized all to zero & NULL */ - static const struct state blank_state; - static so_serial_t next_so = SOS_FIRST; struct state *st; - st = clone_thing(blank_state, "struct state in new_state()"); + st = alloc_thing(struct state, "struct state in new_state()"); st->st_serialno = next_so++; passert(next_so > SOS_FIRST); /* overflow can't happen! */ st->st_whack_sock = NULL_FD; _______________________________________________ Swan-dev mailing list [email protected] https://lists.libreswan.org/mailman/listinfo/swan-dev
