From be4da39131b5f6f2dd2632c4b4b41f0155532459 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 20 Nov 2008 10:10:59 -0800 Subject: [PATCH] Prevent accidentally passing an integer value to IP_ARGS. --- lib/packets.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/packets.h b/lib/packets.h index bad36712d..09ee05dc8 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] -- 2.45.2