From eda13285783d788d08e4911f44730829aaadd433 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 4 Sep 2008 10:46:38 -0700 Subject: [PATCH] Avoid pointer arithmetic on void*. This is a GCC extension not supported by other compilers. --- lib/dhcp-client.c | 2 +- lib/netlink.c | 9 +++++---- lib/ofpbuf.c | 22 +++++++++++----------- switch/datapath.c | 8 ++++---- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index bafa19d0..f62ce5bb 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -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", diff --git a/lib/netlink.c b/lib/netlink.c index e2aa7dbf..cb4e6c1a 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -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); diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 50b471af..8c92fb74 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -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; } diff --git a/switch/datapath.c b/switch/datapath.c index 607347d8..96193002 100644 --- a/switch/datapath.c +++ b/switch/datapath.c @@ -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); } } -- 2.30.2