]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: Clear output broadcast address before filling it in
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 3 Jun 2015 10:46:36 +0000 (12:46 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 3 Jun 2015 10:54:32 +0000 (12:54 +0200)
Since commit 55ace7c4789c8a7408139460f4b639cee00e5125, the sockettest
fails without VIR_TEST_DEBUG set.  The problem is found by test number
42 (co-incidence?), which tests range '192.168.122.1' -
'192.168.122.255' in network '192.168.122.0/24'.  That is supposed to
fail because the end address is equal to the broadcast address.

When comparing these two in 'virSocketAddrEqual(end, &broadcast)',
there is a check for sin_addr as well as for sin_port.  That port,
however, is different when we do not enable test debugging.  With the
testing enabled, the port is 0 (correctly initialized), but without that
it has a random number there.  And that's because the structure is not
initialized anywhere.

By zeroing the structure before filling in the info, we make sure we
return only the address and not any information that was not requested.
And the test work once again.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/util/virsocketaddr.c

index 34f2af31b2e7d6f03daaec98034f61a06ff0f319..81539b3730d4577510290ecbe61bc98b3a753466 100644 (file)
@@ -505,6 +505,8 @@ virSocketAddrBroadcast(const virSocketAddr *addr,
                        const virSocketAddr *netmask,
                        virSocketAddrPtr broadcast)
 {
+    memset(broadcast, 0, sizeof(*broadcast));
+
     if ((addr->data.stor.ss_family != AF_INET) ||
         (netmask->data.stor.ss_family != AF_INET)) {
         broadcast->data.stor.ss_family = AF_UNSPEC;