summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-10-28 22:16:40 (GMT)
committerThomas Graf <tgraf@suug.ch>2010-10-28 22:16:40 (GMT)
commitd0e564548f6eff0a8d49e5e9cb618a8d297a1b98 (patch)
treec62b95570a8b9b5b1c0c30673fad1fdf8a849a2f
parent0fe5b29423c1ad97012a865f1cd8b4f7ff37f143 (diff)
downloadlibnl-d0e564548f6eff0a8d49e5e9cb618a8d297a1b98.zip
libnl-d0e564548f6eff0a8d49e5e9cb618a8d297a1b98.tar.gz
libnl-d0e564548f6eff0a8d49e5e9cb618a8d297a1b98.tar.bz2
Avoid memcpy()/memset() when reserving space for nested attributes
-rw-r--r--lib/attr.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/attr.c b/lib/attr.c
index 298fbb1..8a527eb 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -809,7 +809,8 @@ struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int attrlen)
nla->nla_type = attrtype;
nla->nla_len = nla_attr_size(attrlen);
- memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen));
+ if (attrlen)
+ memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen));
msg->nm_nlh->nlmsg_len = tlen;
NL_DBG(2, "msg %p: Reserved %d bytes at offset +%td for attr %d "
@@ -842,9 +843,11 @@ int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
if (!nla)
return -NLE_NOMEM;
- memcpy(nla_data(nla), data, datalen);
- NL_DBG(2, "msg %p: Wrote %d bytes at offset +%td for attr %d\n",
- msg, datalen, (void *) nla - nlmsg_data(msg->nm_nlh), attrtype);
+ if (datalen > 0) {
+ memcpy(nla_data(nla), data, datalen);
+ NL_DBG(2, "msg %p: Wrote %d bytes at offset +%td for attr %d\n",
+ msg, datalen, (void *) nla - nlmsg_data(msg->nm_nlh), attrtype);
+ }
return 0;
}