Prevent accidentally passing an integer value to IP_ARGS.
authorBen Pfaff <blp@nicira.com>
Thu, 20 Nov 2008 18:10:59 +0000 (10:10 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 20 Nov 2008 18:10:59 +0000 (10:10 -0800)
lib/packets.h

index bad3671..09ee05d 100644 (file)
@@ -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]