mirror of
https://gitee.com/openharmony/third_party_libnl
synced 2025-02-17 09:48:08 +00:00
all: Avoid pointer arithmetic on void *
ISO C requires that the pointer operand to the binary + operator be to a complete object type[0]. [0] http://port70.net/~nsz/c/c11/n1570.html#6.5.6p2
This commit is contained in:
parent
1a88619b72
commit
de72910e6b
@ -37,6 +37,7 @@ warn_cppflags = \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-sign-compare \
|
||||
-Wno-missing-field-initializers \
|
||||
-Wpointer-arith \
|
||||
$(NULL)
|
||||
|
||||
###############################################################################
|
||||
|
@ -478,7 +478,7 @@ struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int attrlen)
|
||||
NL_DBG(2, "msg %p: attr <%p> %d: Reserved %d (%d) bytes at offset +%td "
|
||||
"nlmsg_len=%d\n", msg, nla, nla->nla_type,
|
||||
nla_total_size(attrlen), attrlen,
|
||||
(void *) nla - nlmsg_data(msg->nm_nlh),
|
||||
(char *) nla - (char *) nlmsg_data(msg->nm_nlh),
|
||||
msg->nm_nlh->nlmsg_len);
|
||||
|
||||
return nla;
|
||||
@ -514,7 +514,7 @@ int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
|
||||
memcpy(nla_data(nla), data, datalen);
|
||||
NL_DBG(2, "msg %p: attr <%p> %d: Wrote %d bytes at offset +%td\n",
|
||||
msg, nla, nla->nla_type, datalen,
|
||||
(void *) nla - nlmsg_data(msg->nm_nlh));
|
||||
(char *) nla - (char *) nlmsg_data(msg->nm_nlh));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -917,7 +917,7 @@ static int _nest_end(struct nl_msg *msg, struct nlattr *start, int keep_empty)
|
||||
{
|
||||
size_t pad, len;
|
||||
|
||||
len = (void *) nlmsg_tail(msg->nm_nlh) - (void *) start;
|
||||
len = (char *) nlmsg_tail(msg->nm_nlh) - (char *) start;
|
||||
|
||||
if ( len > USHRT_MAX
|
||||
|| (!keep_empty && len == NLA_HDRLEN)) {
|
||||
@ -996,7 +996,7 @@ void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr)
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
len = (void *) nlmsg_tail(msg->nm_nlh) - (void *) attr;
|
||||
len = (char *) nlmsg_tail(msg->nm_nlh) - (char *) attr;
|
||||
if (len < 0)
|
||||
BUG();
|
||||
else if (len > 0) {
|
||||
|
@ -112,7 +112,7 @@ struct nl_data *nl_data_clone(const struct nl_data *src)
|
||||
int nl_data_append(struct nl_data *data, const void *buf, size_t size)
|
||||
{
|
||||
if (size > 0) {
|
||||
void *d_data = realloc(data->d_data, data->d_size + size);
|
||||
char *d_data = realloc(data->d_data, data->d_size + size);
|
||||
if (!d_data)
|
||||
return -NLE_NOMEM;
|
||||
|
||||
|
@ -260,7 +260,7 @@ void *genlmsg_user_hdr(const struct genlmsghdr *gnlh)
|
||||
*/
|
||||
void *genlmsg_user_data(const struct genlmsghdr *gnlh, const int hdrlen)
|
||||
{
|
||||
return genlmsg_user_hdr(gnlh) + NLMSG_ALIGN(hdrlen);
|
||||
return (char *) genlmsg_user_hdr(gnlh) + NLMSG_ALIGN(hdrlen);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,7 +364,7 @@ void *genlmsg_put(struct nl_msg *msg, uint32_t port, uint32_t seq, int family,
|
||||
NL_DBG(2, "msg %p: Added generic netlink header cmd=%d version=%d\n",
|
||||
msg, cmd, version);
|
||||
|
||||
return nlmsg_data(nlh) + GENL_HDRLEN;
|
||||
return (char *) nlmsg_data(nlh) + GENL_HDRLEN;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -192,7 +192,7 @@ int nl_hash_table_del(nl_hash_table_t *ht, struct nl_object *obj)
|
||||
|
||||
uint32_t nl_hash(void *k, size_t length, uint32_t initval)
|
||||
{
|
||||
return(__nl_hash(k, length, initval));
|
||||
return(__nl_hash((char *) k, length, initval));
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -410,7 +410,7 @@ struct nl_msg *nlmsg_convert(struct nlmsghdr *hdr)
|
||||
*/
|
||||
void *nlmsg_reserve(struct nl_msg *n, size_t len, int pad)
|
||||
{
|
||||
void *buf = n->nm_nlh;
|
||||
char *buf = (char *) n->nm_nlh;
|
||||
size_t nlmsg_len = n->nm_nlh->nlmsg_len;
|
||||
size_t tlen;
|
||||
|
||||
@ -838,7 +838,7 @@ static void print_genl_hdr(FILE *ofd, void *start)
|
||||
static void *print_genl_msg(struct nl_msg *msg, FILE *ofd, struct nlmsghdr *hdr,
|
||||
struct nl_cache_ops *ops, int *payloadlen)
|
||||
{
|
||||
void *data = nlmsg_data(hdr);
|
||||
char *data = nlmsg_data(hdr);
|
||||
|
||||
if (*payloadlen < GENL_HDRLEN)
|
||||
return data;
|
||||
@ -901,7 +901,7 @@ static void dump_attrs(FILE *ofd, struct nlattr *attrs, int attrlen,
|
||||
prefix_line(ofd, prefix);
|
||||
fprintf(ofd, " [PADDING] %d octets\n",
|
||||
padlen);
|
||||
dump_hex(ofd, nla_data(nla) + alen,
|
||||
dump_hex(ofd, (char *) nla_data(nla) + alen,
|
||||
padlen, prefix);
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ struct nl_object *nl_object_clone(struct nl_object *obj)
|
||||
new->ce_mask = obj->ce_mask;
|
||||
|
||||
if (size)
|
||||
memcpy((void *)new + doff, (void *)obj + doff, size);
|
||||
memcpy((char *)new + doff, (char *)obj + doff, size);
|
||||
|
||||
if (ops->oo_clone) {
|
||||
if (ops->oo_clone(new, obj) < 0) {
|
||||
|
@ -465,7 +465,7 @@ int rtnl_ematch_parse_attr(struct nlattr *attr, struct rtnl_ematch_tree **result
|
||||
}
|
||||
|
||||
hdr = nla_data(a);
|
||||
data = nla_data(a) + NLA_ALIGN(sizeof(*hdr));
|
||||
data = (char *) nla_data(a) + NLA_ALIGN(sizeof(*hdr));
|
||||
len = nla_len(a) - NLA_ALIGN(sizeof(*hdr));
|
||||
|
||||
NL_DBG(3, "ematch attribute matchid=%u, kind=%u, flags=%u\n",
|
||||
|
@ -94,7 +94,7 @@ static int nbyte_parse(struct rtnl_ematch *e, void *data, size_t len)
|
||||
if (!(n->pattern = calloc(1, plen)))
|
||||
return -NLE_NOMEM;
|
||||
|
||||
memcpy(n->pattern, data + hdrlen, plen);
|
||||
memcpy(n->pattern, (char *) data + hdrlen, plen);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -117,7 +117,7 @@ static int text_parse(struct rtnl_ematch *e, void *data, size_t len)
|
||||
if (!(t->pattern = calloc(1, t->cfg.pattern_len)))
|
||||
return -NLE_NOMEM;
|
||||
|
||||
memcpy(t->pattern, data + hdrlen, t->cfg.pattern_len);
|
||||
memcpy(t->pattern, (char *) data + hdrlen, t->cfg.pattern_len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -63,8 +63,8 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
|
||||
peer->l_index = ifi->ifi_index;
|
||||
peer->l_flags = ifi->ifi_flags;
|
||||
peer->l_change = ifi->ifi_change;
|
||||
err = nla_parse(peer_tb, IFLA_MAX,
|
||||
nla_data(nla_peer) + sizeof(struct ifinfomsg),
|
||||
err = nla_parse(peer_tb, IFLA_MAX, (struct nlattr *)
|
||||
((char *) nla_data(nla_peer) + sizeof(struct ifinfomsg)),
|
||||
nla_len(nla_peer) - sizeof(struct ifinfomsg),
|
||||
rtln_link_policy);
|
||||
if (err < 0)
|
||||
|
@ -63,7 +63,7 @@ static int mqprio_msg_parser(struct rtnl_tc *tc, void *data)
|
||||
struct nlattr *tb[TCA_MQPRIO_MAX + 1];
|
||||
|
||||
err = nla_parse(tb, TCA_MQPRIO_MAX, (struct nlattr *)
|
||||
(tc->tc_opts->d_data + NLA_ALIGN(sizeof(*qopt))),
|
||||
((char *) tc->tc_opts->d_data + NLA_ALIGN(sizeof(*qopt))),
|
||||
len, mqprio_policy);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
@ -76,7 +76,7 @@ static int netem_msg_parser(struct rtnl_tc *tc, void *data)
|
||||
struct nlattr *tb[TCA_NETEM_MAX+1];
|
||||
|
||||
err = nla_parse(tb, TCA_NETEM_MAX, (struct nlattr *)
|
||||
(tc->tc_opts->d_data + sizeof(*opts)),
|
||||
((char *) tc->tc_opts->d_data + sizeof(*opts)),
|
||||
len, netem_policy);
|
||||
if (err < 0) {
|
||||
free(netem);
|
||||
@ -323,14 +323,14 @@ static int netem_msg_fill_raw(struct rtnl_tc *tc, void *data,
|
||||
* remainder of the message. That's just the way that sch_netem expects it.
|
||||
* Maybe there's a more succinct way to do this at a higher level.
|
||||
*/
|
||||
head = (struct nlattr *)(NLMSG_DATA(msg->nm_nlh) +
|
||||
head = (struct nlattr *)(((char *) NLMSG_DATA(msg->nm_nlh)) +
|
||||
NLMSG_LENGTH(sizeof(struct tcmsg)) - NLMSG_ALIGNTO);
|
||||
|
||||
tail = (struct nlattr *)(((void *) (msg->nm_nlh)) +
|
||||
tail = (struct nlattr *)(((char *) (msg->nm_nlh)) +
|
||||
NLMSG_ALIGN(msg->nm_nlh->nlmsg_len));
|
||||
|
||||
old_len = head->nla_len;
|
||||
head->nla_len = (void *)tail - (void *)head;
|
||||
head->nla_len = (char *)tail - (char *)head;
|
||||
msg->nm_nlh->nlmsg_len += (head->nla_len - old_len);
|
||||
|
||||
return err;
|
||||
|
@ -1472,8 +1472,8 @@ int rtnl_route_build_msg(struct nl_msg *msg, struct rtnl_route *route)
|
||||
nh_encap_build_msg(msg, nh->rtnh_encap) < 0)
|
||||
goto nla_put_failure;
|
||||
|
||||
rtnh->rtnh_len = nlmsg_tail(msg->nm_nlh) -
|
||||
(void *) rtnh;
|
||||
rtnh->rtnh_len = (char *) nlmsg_tail(msg->nm_nlh) -
|
||||
(char *) rtnh;
|
||||
}
|
||||
|
||||
nla_nest_end(msg, multipath);
|
||||
|
@ -682,7 +682,7 @@ int xfrmnl_sa_parse(struct nlmsghdr *n, struct xfrmnl_sa **result)
|
||||
}
|
||||
else if (n->nlmsg_type == XFRM_MSG_DELSA)
|
||||
{
|
||||
sa_info = (struct xfrm_usersa_info*)(nlmsg_data(n) + sizeof (struct xfrm_usersa_id) + NLA_HDRLEN);
|
||||
sa_info = (struct xfrm_usersa_info*)((char *)nlmsg_data(n) + sizeof (struct xfrm_usersa_id) + NLA_HDRLEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -532,7 +532,7 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
sp->ce_msgtype = n->nlmsg_type;
|
||||
if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
|
||||
{
|
||||
sp_info = (struct xfrm_userpolicy_info*)(nlmsg_data(n) + sizeof (struct xfrm_userpolicy_id) + NLA_HDRLEN);
|
||||
sp_info = (struct xfrm_userpolicy_info*)((char *)nlmsg_data(n) + sizeof (struct xfrm_userpolicy_id) + NLA_HDRLEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -53,9 +53,9 @@ static void print_class(struct nl_object *obj, void *arg)
|
||||
|
||||
leaf = rtnl_class_leaf_qdisc(class, qdisc_cache);
|
||||
if (leaf)
|
||||
print_qdisc((struct nl_object *) leaf, arg + 2);
|
||||
print_qdisc((struct nl_object *) leaf, (char *) arg + 2);
|
||||
|
||||
print_tc_childs(TC_CAST(class), arg + 2);
|
||||
print_tc_childs(TC_CAST(class), (char *) arg + 2);
|
||||
|
||||
if (rtnl_cls_alloc_cache(sock, ifindex, parent, &cls_cache) < 0)
|
||||
return;
|
||||
@ -88,7 +88,7 @@ static void print_qdisc(struct nl_object *obj, void *arg)
|
||||
params.dp_prefix = (int)(long) arg;
|
||||
nl_object_dump(obj, ¶ms);
|
||||
|
||||
print_tc_childs(TC_CAST(qdisc), arg + 2);
|
||||
print_tc_childs(TC_CAST(qdisc), (char *) arg + 2);
|
||||
|
||||
if (rtnl_cls_alloc_cache(sock, ifindex, parent, &cls_cache) < 0)
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user