[ovs-dev] [PATCH 3/3] clang: Fix the alignment warning.

Alex Wang alexw at nicira.com
Mon Jul 22 16:19:58 UTC 2013


This commit fixes the warning issued by 'clang' when pointer is casted
to one with greater alignment.

Signed-off-by: Alex Wang <alexw at nicira.com>
---
 lib/hash.c             |    6 +++---
 lib/jhash.c            |   10 +++++-----
 lib/mac-learning.c     |    4 ++--
 lib/netdev-linux.c     |    3 ++-
 lib/netlink.c          |    7 +++----
 lib/nx-match.c         |   12 +++++++-----
 lib/nx-match.h         |    2 +-
 lib/odp-util.c         |    3 ++-
 lib/ofp-actions.c      |   27 ++++++++++++++-------------
 lib/ofp-actions.h      |    2 +-
 lib/ofp-util.c         |    7 ++++---
 lib/ofpbuf.c           |    7 +++++++
 lib/ofpbuf.h           |    1 +
 lib/ovs-atomic-gcc4+.h |    4 ++--
 lib/packets.c          |    8 +++++---
 lib/route-table.c      |    2 +-
 lib/rtnetlink-link.c   |    4 ++--
 lib/socket-util.c      |    5 +++--
 lib/stream-tcp.c       |    3 ++-
 lib/util.h             |    4 ++++
 utilities/ovs-dpctl.c  |    3 ++-
 utilities/ovs-ofctl.c  |    4 ++--
 22 files changed, 75 insertions(+), 53 deletions(-)

diff --git a/lib/hash.c b/lib/hash.c
index e954d78..8f34493 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -29,15 +29,15 @@ hash_3words(uint32_t a, uint32_t b, uint32_t c)
 uint32_t
 hash_bytes(const void *p_, size_t n, uint32_t basis)
 {
-    const uint8_t *p = p_;
+    const uint32_t *p = p_;
     size_t orig_n = n;
     uint32_t hash;
 
     hash = basis;
     while (n >= 4) {
-        hash = mhash_add(hash, get_unaligned_u32((const uint32_t *) p));
+        hash = mhash_add(hash, get_unaligned_u32(p));
         n -= 4;
-        p += 4;
+        p += 1;
     }
 
     if (n) {
diff --git a/lib/jhash.c b/lib/jhash.c
index 4ec2871..c08c368 100644
--- a/lib/jhash.c
+++ b/lib/jhash.c
@@ -96,18 +96,18 @@ jhash_words(const uint32_t *p, size_t n, uint32_t basis)
 uint32_t
 jhash_bytes(const void *p_, size_t n, uint32_t basis)
 {
-    const uint8_t *p = p_;
+    const uint32_t *p = p_;
     uint32_t a, b, c;
 
     a = b = c = 0xdeadbeef + n + basis;
 
     while (n >= 12) {
-        a += get_unaligned_u32((uint32_t *) p);
-        b += get_unaligned_u32((uint32_t *) (p + 4));
-        c += get_unaligned_u32((uint32_t *) (p + 8));
+        a += get_unaligned_u32(p);
+        b += get_unaligned_u32(p + 1);
+        c += get_unaligned_u32(p + 2);
         jhash_mix(&a, &b, &c);
         n -= 12;
-        p += 12;
+        p += 3;
     }
 
     if (n) {
diff --git a/lib/mac-learning.c b/lib/mac-learning.c
index ca0ccb8..0fa0459 100644
--- a/lib/mac-learning.c
+++ b/lib/mac-learning.c
@@ -49,8 +49,8 @@ static uint32_t
 mac_table_hash(const struct mac_learning *ml, const uint8_t mac[ETH_ADDR_LEN],
                uint16_t vlan)
 {
-    unsigned int mac1 = get_unaligned_u32((uint32_t *) mac);
-    unsigned int mac2 = get_unaligned_u16((uint16_t *) (mac + 4));
+    unsigned int mac1 = get_unaligned_u32(ALIGNED_CAST(uint32_t *, mac));
+    unsigned int mac2 = get_unaligned_u16(ALIGNED_CAST(uint16_t *, (mac + 4)));
     return hash_3words(mac1, mac2 | (vlan << 16), ml->secret);
 }
 
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 05877c1..c2f09ea 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -4546,7 +4546,8 @@ netdev_linux_get_ipv4(const struct netdev *netdev, struct in_addr *ip,
     ifr.ifr_addr.sa_family = AF_INET;
     error = netdev_linux_do_ioctl(netdev_get_name(netdev), &ifr, cmd, cmd_name);
     if (!error) {
-        const struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
+        const struct sockaddr_in *sin = ALIGNED_CAST(struct sockaddr_in *,
+                                                     &ifr.ifr_addr);
         *ip = sin->sin_addr;
     }
     return error;
diff --git a/lib/netlink.c b/lib/netlink.c
index a686784..1f96b18 100644
--- a/lib/netlink.c
+++ b/lib/netlink.c
@@ -712,7 +712,7 @@ nl_policy_parse(const struct ofpbuf *msg, size_t nla_offset,
     }
 
     NL_ATTR_FOR_EACH (nla, left,
-                      (struct nlattr *) ((char *) msg->data + nla_offset),
+                      (struct nlattr *) ofpbuf_forward_ref(msg, nla_offset),
                       msg->size - nla_offset)
     {
         uint16_t type = nl_attr_type(nla);
@@ -777,9 +777,8 @@ nl_attr_find__(const struct nlattr *attrs, size_t size, uint16_t type)
 const struct nlattr *
 nl_attr_find(const struct ofpbuf *buf, size_t hdr_len, uint16_t type)
 {
-    const uint8_t *start = (const uint8_t *) buf->data + hdr_len;
-    return nl_attr_find__((const struct nlattr *) start, buf->size - hdr_len,
-                          type);
+    const struct nlattr *start = ofpbuf_forward_ref(buf, hdr_len);
+    return nl_attr_find__(start, buf->size - hdr_len, type);
 }
 
 /* Returns the first Netlink attribute within 'nla' with the specified
diff --git a/lib/nx-match.c b/lib/nx-match.c
index 3a6d7cc..2da06a2 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -744,7 +744,7 @@ oxm_put_match(struct ofpbuf *b, const struct match *match)
     match_len = nx_put_raw(b, true, match, cookie, cookie_mask) + sizeof *omh;
     ofpbuf_put_zeros(b, ROUND_UP(match_len, 8) - match_len);
 
-    omh = (struct ofp11_match_header *)((char *)b->data + start_len);
+    omh = (struct ofp11_match_header *) ofpbuf_forward_ref(b, start_len);
     omh->type = htons(OFPMT_OXM);
     omh->length = htons(match_len);
 
@@ -807,9 +807,10 @@ nx_match_to_string(const uint8_t *p, unsigned int match_len)
 }
 
 char *
-oxm_match_to_string(const uint8_t *p, unsigned int match_len)
+oxm_match_to_string(const struct ofpbuf *p, unsigned int match_len)
 {
-    const struct ofp11_match_header *omh = (struct ofp11_match_header *)p;
+    const struct ofp11_match_header *omh = (struct ofp11_match_header *)
+                                               p->data;
     uint16_t match_len_;
     struct ds s;
 
@@ -837,7 +838,8 @@ oxm_match_to_string(const uint8_t *p, unsigned int match_len)
         goto err;
     }
 
-    return nx_match_to_string(p + sizeof *omh, match_len - sizeof *omh);
+    return nx_match_to_string(ofpbuf_forward_ref(p, sizeof *omh),
+                              match_len - sizeof *omh);
 
 err:
     return ds_steal_cstr(&s);
@@ -997,7 +999,7 @@ oxm_match_from_string(const char *s, struct ofpbuf *b)
     match_len = nx_match_from_string_raw(s, b) + sizeof *omh;
     ofpbuf_put_zeros(b, ROUND_UP(match_len, 8) - match_len);
 
-    omh = (struct ofp11_match_header *)((char *)b->data + start_len);
+    omh = (struct ofp11_match_header *) ofpbuf_forward_ref(b, start_len);
     omh->type = htons(OFPMT_OXM);
     omh->length = htons(match_len);
 
diff --git a/lib/nx-match.h b/lib/nx-match.h
index b03688b..a6b7c52 100644
--- a/lib/nx-match.h
+++ b/lib/nx-match.h
@@ -54,7 +54,7 @@ int nx_put_match(struct ofpbuf *, const struct match *,
 int oxm_put_match(struct ofpbuf *, const struct match *);
 
 char *nx_match_to_string(const uint8_t *, unsigned int match_len);
-char *oxm_match_to_string(const uint8_t *, unsigned int match_len);
+char *oxm_match_to_string(const struct ofpbuf *, unsigned int match_len);
 int nx_match_from_string(const char *, struct ofpbuf *);
 int oxm_match_from_string(const char *, struct ofpbuf *);
 
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 5a32221..3c3063d 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -2512,7 +2512,8 @@ uint32_t
 odp_flow_key_hash(const struct nlattr *key, size_t key_len)
 {
     BUILD_ASSERT_DECL(!(NLA_ALIGNTO % sizeof(uint32_t)));
-    return hash_words((const uint32_t *) key, key_len / sizeof(uint32_t), 0);
+    return hash_words(ALIGNED_CAST(const uint32_t *, key),
+                      key_len / sizeof(uint32_t), 0);
 }
 
 static void
diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index 899928a..52d0266 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -336,7 +336,7 @@ ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
         break;
 
     case OFPUTIL_NXAST_WRITE_METADATA:
-        nawm = (const struct nx_action_write_metadata *) a;
+        nawm = ALIGNED_CAST(const struct nx_action_write_metadata *, a);
         error = metadata_from_nxast(nawm, out);
         break;
 
@@ -356,7 +356,7 @@ ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
 
     case OFPUTIL_NXAST_REG_LOAD:
         error = nxm_reg_load_from_openflow(
-            (const struct nx_action_reg_load *) a, out);
+            ALIGNED_CAST(const struct nx_action_reg_load *, a), out);
         break;
 
     case OFPUTIL_NXAST_STACK_PUSH:
@@ -375,7 +375,7 @@ ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
         break;
 
     case OFPUTIL_NXAST_SET_TUNNEL64:
-        nast64 = (const struct nx_action_set_tunnel64 *) a;
+        nast64 = ALIGNED_CAST(const struct nx_action_set_tunnel64 *, a);
         tunnel = ofpact_put_SET_TUNNEL(out);
         tunnel->ofpact.compat = code;
         tunnel->tun_id = ntohll(nast64->tun_id);
@@ -402,7 +402,8 @@ ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
         break;
 
     case OFPUTIL_NXAST_LEARN:
-        error = learn_from_openflow((const struct nx_action_learn *) a, out);
+        error = learn_from_openflow(
+            ALIGNED_CAST(const struct nx_action_learn *, a), out);
         break;
 
     case OFPUTIL_NXAST_EXIT:
@@ -881,7 +882,7 @@ ofpacts_from_openflow11(const union ofp_action *in, size_t n_in,
     instruction_get_##ENUM(const struct ofp11_instruction *inst)\
     {                                                           \
         ovs_assert(inst->type == htons(ENUM));                  \
-        return (struct STRUCT *)inst;                           \
+        return ALIGNED_CAST(struct STRUCT *, inst);             \
     }                                                           \
                                                                 \
     static inline void                                          \
@@ -1070,10 +1071,10 @@ decode_openflow11_instructions(const struct ofp11_instruction insts[],
 
 static void
 get_actions_from_instruction(const struct ofp11_instruction *inst,
-                         const union ofp_action **actions,
-                         size_t *n_actions)
+                             const union ofp_action **actions,
+                             size_t *n_actions)
 {
-    *actions = (const union ofp_action *) (inst + 1);
+    *actions = ALIGNED_CAST(const union ofp_action *, (inst + 1));
     *n_actions = (ntohs(inst->len) - sizeof *inst) / OFP11_INSTRUCTION_ALIGN;
 }
 
@@ -1140,8 +1141,8 @@ ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow,
         const struct ofp13_instruction_meter *oim;
         struct ofpact_meter *om;
 
-        oim = (const struct ofp13_instruction_meter *)
-            insts[OVSINST_OFPIT13_METER];
+        oim = ALIGNED_CAST(const struct ofp13_instruction_meter *,
+              insts[OVSINST_OFPIT13_METER]);
 
         om = ofpact_put_METER(ofpacts);
         om->meter_id = ntohl(oim->meter_id);
@@ -1167,8 +1168,8 @@ ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow,
         const struct ofp11_instruction_write_metadata *oiwm;
         struct ofpact_metadata *om;
 
-        oiwm = (const struct ofp11_instruction_write_metadata *)
-            insts[OVSINST_OFPIT11_WRITE_METADATA];
+        oiwm = ALIGNED_CAST(const struct ofp11_instruction_write_metadata *,
+                            insts[OVSINST_OFPIT11_WRITE_METADATA]);
 
         om = ofpact_put_WRITE_METADATA(ofpacts);
         om->metadata = oiwm->metadata;
@@ -1436,7 +1437,7 @@ ofpact_note_to_nxast(const struct ofpact_note *note, struct ofpbuf *out)
     if (remainder) {
         ofpbuf_put_zeros(out, OFP_ACTION_ALIGN - remainder);
     }
-    nan = (struct nx_action_note *)((char *)out->data + start_ofs);
+    nan = (struct nx_action_note *) ofpbuf_forward_ref(out, start_ofs);
     nan->len = htons(out->size - start_ofs);
 }
 
diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
index b97afd0..ca33ca8 100644
--- a/lib/ofp-actions.h
+++ b/lib/ofp-actions.h
@@ -582,7 +582,7 @@ void *ofpact_put(struct ofpbuf *, enum ofpact_type, size_t len);
     ofpact_get_##ENUM(const struct ofpact *ofpact)                      \
     {                                                                   \
         ovs_assert(ofpact->type == OFPACT_##ENUM);                      \
-        return (struct STRUCT *) ofpact;                                \
+        return ALIGNED_CAST(struct STRUCT *, ofpact);                   \
     }                                                                   \
                                                                         \
     static inline struct STRUCT *                                       \
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index bc85797..25bfa92 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -1293,7 +1293,7 @@ ofputil_decode_hello_bitmap(const struct ofp_hello_elem_header *oheh,
                             uint32_t *allowed_versionsp)
 {
     uint16_t bitmap_len = ntohs(oheh->length) - sizeof *oheh;
-    const ovs_be32 *bitmap = (const ovs_be32 *) (oheh + 1);
+    const ovs_be32 *bitmap = ALIGNED_CAST(const ovs_be32 *, (oheh + 1));
     uint32_t allowed_versions;
 
     if (!bitmap_len || bitmap_len % sizeof *bitmap) {
@@ -1397,7 +1397,7 @@ ofputil_encode_hello(uint32_t allowed_versions)
         oheh = ofpbuf_put_zeros(msg, ROUND_UP(map_len + sizeof *oheh, 8));
         oheh->type = htons(OFPHET_VERSIONBITMAP);
         oheh->length = htons(map_len + sizeof *oheh);
-        *(ovs_be32 *)(oheh + 1) = htonl(allowed_versions);
+        *ALIGNED_CAST(ovs_be32 *, (oheh + 1)) = htonl(allowed_versions);
 
         ofpmsg_update_length(msg);
     }
@@ -1750,7 +1750,8 @@ ofputil_pull_bands(struct ofpbuf *msg, size_t len, uint16_t *n_bands,
             ((struct ofp13_meter_band_dscp_remark *)ombh)->prec_level : 0;
         n++;
         len -= ombh_len;
-        ombh = (struct ofp13_meter_band_header *)(((char *)ombh) + ombh_len);
+        ombh = ALIGNED_CAST(struct ofp13_meter_band_header *,
+                            (((char *)ombh) + ombh_len));
     }
     if (len) {
         return OFPERR_OFPBRC_BAD_LEN;
diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c
index f7145db..6aaacb6 100644
--- a/lib/ofpbuf.c
+++ b/lib/ofpbuf.c
@@ -572,3 +572,10 @@ ofpbuf_list_delete(struct list *list)
         ofpbuf_delete(b);
     }
 }
+
+/* Return the pointer that is 't' bytes forward from 'b->data'. */
+void *
+ofpbuf_forward_ref(const struct ofpbuf *b, size_t t)
+{
+    return (void *)((char *) b->data + t);
+}
diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h
index 0c12162..c6cda7e 100644
--- a/lib/ofpbuf.h
+++ b/lib/ofpbuf.h
@@ -96,6 +96,7 @@ void ofpbuf_padto(struct ofpbuf *, size_t);
 void ofpbuf_clear(struct ofpbuf *);
 void *ofpbuf_pull(struct ofpbuf *, size_t);
 void *ofpbuf_try_pull(struct ofpbuf *, size_t);
+void *ofpbuf_forward_ref(const struct ofpbuf *, size_t);
 
 void *ofpbuf_steal_data(struct ofpbuf *);
 
diff --git a/lib/ovs-atomic-gcc4+.h b/lib/ovs-atomic-gcc4+.h
index b8649ed..4476162 100644
--- a/lib/ovs-atomic-gcc4+.h
+++ b/lib/ovs-atomic-gcc4+.h
@@ -117,7 +117,7 @@ typedef enum {
     __builtin_choose_expr(                                              \
         __builtin_types_compatible_p(typeof(OBJECT), struct locked_uint64), \
         (THEN), (ELSE))
-#define AS_LOCKED_UINT64(OBJECT) ((struct locked_uint64 *) (OBJECT))
+#define AS_LOCKED_UINT64(OBJECT) ((struct locked_uint64 *) (void *) (OBJECT))
 #define AS_UINT64(OBJECT) ((uint64_t *) (OBJECT))
 struct locked_uint64 {
     uint64_t value;
@@ -135,7 +135,7 @@ uint64_t locked_uint64_and(struct locked_uint64 *, uint64_t arg);
     __builtin_choose_expr(                                              \
         __builtin_types_compatible_p(typeof(OBJECT), struct locked_int64), \
         (THEN), (ELSE))
-#define AS_LOCKED_INT64(OBJECT) ((struct locked_int64 *) (OBJECT))
+#define AS_LOCKED_INT64(OBJECT) ((struct locked_int64 *) (void *) (OBJECT))
 #define AS_INT64(OBJECT) ((int64_t *) (OBJECT))
 struct locked_int64 {
     int64_t value;
diff --git a/lib/packets.c b/lib/packets.c
index 7fe6513..3702ad9 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -246,7 +246,8 @@ set_ethertype(struct ofpbuf *packet, ovs_be16 eth_type)
 
     if (eh->eth_type == htons(ETH_TYPE_VLAN)) {
         ovs_be16 *p;
-        p = (ovs_be16 *)((char *)(packet->l2_5 ? packet->l2_5 : packet->l3) - 2);
+        p = ALIGNED_CAST(ovs_be16 *,
+                ((char *)(packet->l2_5 ? packet->l2_5 : packet->l3) - 2));
         *p = eth_type;
     } else {
         eh->eth_type = eth_type;
@@ -666,7 +667,7 @@ packet_rh_present(struct ofpbuf *packet)
     if (remaining < sizeof *nh) {
         return false;
     }
-    nh = (struct ip6_hdr *)data;
+    nh = ALIGNED_CAST(struct ip6_hdr *, data);
     data += sizeof *nh;
     remaining -= sizeof *nh;
     nexthdr = nh->ip6_nxt;
@@ -702,7 +703,8 @@ packet_rh_present(struct ofpbuf *packet)
             nexthdr = ext_hdr->ip6e_nxt;
             len = (ext_hdr->ip6e_len + 2) * 4;
         } else if (nexthdr == IPPROTO_FRAGMENT) {
-            const struct ip6_frag *frag_hdr = (struct ip6_frag *)data;
+            const struct ip6_frag *frag_hdr = ALIGNED_CAST(struct ip6_frag *,
+                                                           data);
 
             nexthdr = frag_hdr->ip6f_nxt;
             len = sizeof *frag_hdr;
diff --git a/lib/route-table.c b/lib/route-table.c
index d572e8c..d7204a0 100644
--- a/lib/route-table.c
+++ b/lib/route-table.c
@@ -270,7 +270,7 @@ route_table_parse(struct ofpbuf *buf, struct route_table_msg *change)
         const struct nlmsghdr *nlmsg;
 
         nlmsg = buf->data;
-        rtm = (const struct rtmsg *) ((const char *) buf->data + NLMSG_HDRLEN);
+        rtm = (const struct rtmsg *) ofpbuf_forward_ref(buf, NLMSG_HDRLEN);
 
         if (rtm->rtm_family != AF_INET) {
             VLOG_DBG_RL(&rl, "received non AF_INET rtnetlink route message");
diff --git a/lib/rtnetlink-link.c b/lib/rtnetlink-link.c
index 459e485..3ca1959 100644
--- a/lib/rtnetlink-link.c
+++ b/lib/rtnetlink-link.c
@@ -59,8 +59,8 @@ rtnetlink_link_parse(struct ofpbuf *buf,
         const struct ifinfomsg *ifinfo;
 
         nlmsg  = buf->data;
-        ifinfo = ((const struct ifinfomsg *)
-                  ((const char *) buf->data + NLMSG_HDRLEN));
+        ifinfo = ((const struct ifinfomsg *) ofpbuf_forward_ref(buf,
+                                                                NLMSG_HDRLEN));
 
         change->nlmsg_type     = nlmsg->nlmsg_type;
         change->ifi_index      = ifinfo->ifi_index;
diff --git a/lib/socket-util.c b/lib/socket-util.c
index fa55480..98f1147 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -197,7 +197,8 @@ lookup_hostname(const char *host_name, struct in_addr *addr)
 
     switch (getaddrinfo(host_name, NULL, &hints, &result)) {
     case 0:
-        *addr = ((struct sockaddr_in *) result->ai_addr)->sin_addr;
+        *addr = (ALIGNED_CAST(struct sockaddr_in *,
+                              result->ai_addr))->sin_addr;
         freeaddrinfo(result);
         return 0;
 
@@ -1318,7 +1319,7 @@ recv_data_and_fds(int sock,
             goto error;
         } else {
             size_t n_fds = (p->cmsg_len - CMSG_LEN(0)) / sizeof *fds;
-            const int *fds_data = (const int *) CMSG_DATA(p);
+            const int *fds_data = ALIGNED_CAST(const int *, CMSG_DATA(p));
 
             ovs_assert(n_fds > 0);
             if (n_fds > SOUTIL_MAX_FDS) {
diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c
index d507208..a4cdf45 100644
--- a/lib/stream-tcp.c
+++ b/lib/stream-tcp.c
@@ -130,7 +130,8 @@ static int
 ptcp_accept(int fd, const struct sockaddr *sa, size_t sa_len,
             struct stream **streamp)
 {
-    const struct sockaddr_in *sin = (const struct sockaddr_in *) sa;
+    const struct sockaddr_in *sin = ALIGNED_CAST(const struct sockaddr_in *,
+                                                 sa);
     char name[128];
 
     if (sa_len == sizeof(struct sockaddr_in) && sin->sin_family == AF_INET) {
diff --git a/lib/util.h b/lib/util.h
index 911ad32..0db41be 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -193,6 +193,10 @@ is_pow2(uintmax_t x)
 #define ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER) \
     ((OBJECT) = OBJECT_CONTAINING(POINTER, OBJECT, MEMBER), (void) 0)
 
+/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
+ * (void *). This is to suppress the alignment warning issued by clang. */
+#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index e285ed5..fa78b53 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -997,7 +997,8 @@ sort_output_actions(struct nlattr *actions, size_t length)
     }
     if (first_output) {
         uint8_t *end = (uint8_t *) actions + length;
-        sort_output_actions__(first_output, (struct nlattr *) end);
+        sort_output_actions__(first_output,
+                              ALIGNED_CAST(struct nlattr *, end));
     }
 }
 
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 2622255..68b73bf 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -2335,7 +2335,7 @@ ofctl_parse_nxm__(bool oxm)
             ofpbuf_init(&nx_match, 0);
             if (oxm) {
                 match_len = oxm_put_match(&nx_match, &match);
-                out = oxm_match_to_string(nx_match.data, match_len);
+                out = oxm_match_to_string(&nx_match, match_len);
             } else {
                 match_len = nx_put_match(&nx_match, &match,
                                          cookie, cookie_mask);
@@ -2775,7 +2775,7 @@ ofctl_check_vlan(int argc OVS_UNUSED, char *argv[])
     /* Convert to and from OXM. */
     ofpbuf_init(&nxm, 0);
     nxm_match_len = oxm_put_match(&nxm, &match);
-    nxm_s = oxm_match_to_string(nxm.data, nxm_match_len);
+    nxm_s = oxm_match_to_string(&nxm, nxm_match_len);
     error = oxm_pull_match(&nxm, &nxm_match);
     printf("OXM: %s -> ", nxm_s);
     if (error) {
-- 
1.7.9.5




More information about the dev mailing list