Avoid pointer arithmetic on void*.
authorBen Pfaff <blp@nicira.com>
Thu, 4 Sep 2008 17:46:38 +0000 (10:46 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 4 Sep 2008 20:53:26 +0000 (13:53 -0700)
This is a GCC extension not supported by other compilers.

lib/dhcp-client.c
lib/netlink.c
lib/ofpbuf.c
switch/datapath.c

index bafa19d..f62ce5b 100644 (file)
@@ -914,7 +914,7 @@ do_receive_msg(struct dhclient *cli, struct dhcp_msg *msg)
             continue;
         }
 
-        ofpbuf_pull(&b, b.l7 - b.data);
+        ofpbuf_pull(&b, (char *)b.l7 - (char*)b.data);
         error = dhcp_parse(msg, &b);
         if (!error) {
             VLOG_DBG_RL(&rl, "received %s",
index e2aa7db..cb4e6c1 100644 (file)
@@ -790,7 +790,7 @@ nl_policy_parse(const struct ofpbuf *msg, const struct nl_policy policy[],
     tail = ofpbuf_tail(msg);
 
     while (p < tail) {
-        size_t offset = p - msg->data;
+        size_t offset = (char*)p - (char*)msg->data;
         struct nlattr *nla = p;
         size_t len, aligned_len;
         uint16_t type;
@@ -803,10 +803,11 @@ nl_policy_parse(const struct ofpbuf *msg, const struct nl_policy policy[],
         }
         len = nla->nla_len - NLA_HDRLEN;
         aligned_len = NLA_ALIGN(len);
-        if (aligned_len > tail - p) {
+        if (aligned_len > (char*)tail - (char*)p) {
             VLOG_DBG_RL(&rl, "%zu: attr %"PRIu16" aligned data len (%zu) "
                         "> bytes left (%tu)",
-                        offset, nla->nla_type, aligned_len, tail - p);
+                        offset, nla->nla_type, aligned_len,
+                        (char*)tail - (char*)p);
             return false;
         }
 
@@ -844,7 +845,7 @@ nl_policy_parse(const struct ofpbuf *msg, const struct nl_policy policy[],
         } else {
             /* Skip attribute type that we don't care about. */
         }
-        p += NLA_ALIGN(nla->nla_len);
+        p = (char*)p + NLA_ALIGN(nla->nla_len);
     }
     if (n_required) {
         VLOG_DBG_RL(&rl, "%zu required attrs missing", n_required);
index 50b471a..8c92fb7 100644 (file)
@@ -117,7 +117,7 @@ ofpbuf_delete(struct ofpbuf *b)
 size_t
 ofpbuf_headroom(struct ofpbuf *b) 
 {
-    return b->data - b->base;
+    return (char*)b->data - (char*)b->base;
 }
 
 /* Returns the number of bytes that may be appended to the tail end of ofpbuf
@@ -125,7 +125,7 @@ ofpbuf_headroom(struct ofpbuf *b)
 size_t
 ofpbuf_tailroom(struct ofpbuf *b) 
 {
-    return ofpbuf_end(b) - ofpbuf_tail(b);
+    return (char*)ofpbuf_end(b) - (char*)ofpbuf_tail(b);
 }
 
 /* Ensures that 'b' has room for at least 'size' bytes at its tail end,
@@ -136,23 +136,23 @@ ofpbuf_prealloc_tailroom(struct ofpbuf *b, size_t size)
     if (size > ofpbuf_tailroom(b)) {
         size_t new_allocated = b->allocated + MAX(size, 64);
         void *new_base = xmalloc(new_allocated);
-        uintptr_t base_delta = new_base - b->base;
+        uintptr_t base_delta = (char*)new_base - (char*)b->base;
         memcpy(new_base, b->base, b->allocated);
         free(b->base);
         b->base = new_base;
         b->allocated = new_allocated;
-        b->data += base_delta;
+        b->data = (char*)b->data + base_delta;
         if (b->l2) {
-            b->l2 += base_delta;
+            b->l2 = (char*)b->l2 + base_delta;
         }
         if (b->l3) {
-            b->l3 += base_delta;
+            b->l3 = (char*)b->l3 + base_delta;
         }
         if (b->l4) {
-            b->l4 += base_delta;
+            b->l4 = (char*)b->l4 + base_delta;
         }
         if (b->l7) {
-            b->l7 += base_delta;
+            b->l7 = (char*)b->l7 + base_delta;
         }
     }
 }
@@ -194,14 +194,14 @@ ofpbuf_reserve(struct ofpbuf *b, size_t size)
 {
     assert(!b->size);
     ofpbuf_prealloc_tailroom(b, size);
-    b->data += size;
+    b->data = (char*)b->data + size;
 }
 
 void *
 ofpbuf_push_uninit(struct ofpbuf *b, size_t size) 
 {
     ofpbuf_prealloc_headroom(b, size);
-    b->data -= size;
+    b->data = (char*)b->data - size;
     b->size += size;
     return b->data;
 }
@@ -261,7 +261,7 @@ ofpbuf_pull(struct ofpbuf *b, size_t size)
 {
     void *data = b->data;
     assert(b->size >= size);
-    b->data += size;
+    b->data = (char*)b->data + size;
     b->size -= size;
     return data;
 }
index 607347d..9619300 100644 (file)
@@ -328,7 +328,7 @@ dp_run(struct datapath *dp)
             const int hard_header = VLAN_ETH_HEADER_LEN;
             const int mtu = netdev_get_mtu(p->netdev);
             buffer = ofpbuf_new(headroom + hard_header + mtu);
-            buffer->data += headroom;
+            buffer->data = (char*)buffer->data + headroom;
         }
         error = netdev_recv(p->netdev, buffer);
         if (!error) {
@@ -1041,7 +1041,7 @@ modify_vlan(struct ofpbuf *buffer,
             
             veh = ofpbuf_push_uninit(buffer, VLAN_HEADER_LEN);
             memcpy(veh, &tmp, sizeof tmp);
-            buffer->l2 -= VLAN_HEADER_LEN;
+            buffer->l2 = (char*)buffer->l2 - VLAN_HEADER_LEN;
         }
     } else  {
         /* Remove an existing vlan header if it exists */
@@ -1054,8 +1054,8 @@ modify_vlan(struct ofpbuf *buffer,
             tmp.eth_type = veh->veth_next_type;
             
             buffer->size -= VLAN_HEADER_LEN;
-            buffer->data += VLAN_HEADER_LEN;
-            buffer->l2 += VLAN_HEADER_LEN;
+            buffer->data = (char*)buffer->data + VLAN_HEADER_LEN;
+            buffer->l2 = (char*)buffer->l2 + VLAN_HEADER_LEN;
             memcpy(buffer->data, &tmp, sizeof tmp);
         }
     }