From: Ben Pfaff Date: Thu, 20 Nov 2008 18:10:59 +0000 (-0800) Subject: Prevent accidentally passing an integer value to IP_ARGS. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be4da39131b5f6f2dd2632c4b4b41f0155532459;p=openvswitch Prevent accidentally passing an integer value to IP_ARGS. --- diff --git a/lib/packets.h b/lib/packets.h index bad36712..09ee05dc 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -160,9 +160,13 @@ struct vlan_eth_header { } __attribute__((packed)); BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header)); +/* The "(void) (ip)[0]" below has no effect on the value, since it's the first + * argument of a comma expression, but it makes sure that 'ip' is a pointer. + * This is useful since a common mistake is to pass an integer instead of a + * pointer to IP_ARGS. */ #define IP_FMT "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8 #define IP_ARGS(ip) \ - ((uint8_t *) ip)[0], \ + ((void) (ip)[0], ((uint8_t *) ip)[0]), \ ((uint8_t *) ip)[1], \ ((uint8_t *) ip)[2], \ ((uint8_t *) ip)[3]