diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-10-28 22:16:40 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-28 22:16:40 (GMT) |
commit | d0e564548f6eff0a8d49e5e9cb618a8d297a1b98 (patch) | |
tree | c62b95570a8b9b5b1c0c30673fad1fdf8a849a2f | |
parent | 0fe5b29423c1ad97012a865f1cd8b4f7ff37f143 (diff) | |
download | libnl-d0e564548f6eff0a8d49e5e9cb618a8d297a1b98.zip libnl-d0e564548f6eff0a8d49e5e9cb618a8d297a1b98.tar.gz libnl-d0e564548f6eff0a8d49e5e9cb618a8d297a1b98.tar.bz2 |
Avoid memcpy()/memset() when reserving space for nested attributes
-rw-r--r-- | lib/attr.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -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; } |