diff options
author | Jan Engelhardt <jengelh@medozas.de> | 2010-11-08 01:10:56 +0100 |
---|---|---|
committer | Jan Engelhardt <jengelh@medozas.de> | 2010-11-16 12:23:25 +0100 |
commit | 478dc5f4ab8d0a639d1bafe3bd53ff3309727836 (patch) | |
tree | 7515de010d9e92dd98fd9b994181a3ac5b5b9f99 /src/attr.c | |
parent | bb8c40e9ef7cb39edd144067d65378c49b837205 (diff) | |
download | libmnl-478dc5f4ab8d0a639d1bafe3bd53ff3309727836.tar.gz libmnl-478dc5f4ab8d0a639d1bafe3bd53ff3309727836.zip |
attr: avoid multiple definition of hidden variable
When nesting two mnl_attr_for_each loops, the __len__ variable will be
declared twice, eliciting a warning when -Wshadow is turned on. There
can also be warnings in pre-C99 because declarations and code are
mixed. Do without any temporaries that are not explicitly specified as
macro parameters.
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'src/attr.c')
-rw-r--r-- | src/attr.c | 17 |
1 files changed, 5 insertions, 12 deletions
@@ -106,9 +106,8 @@ bool mnl_attr_ok(const struct nlattr *attr, int len) * as parameter. You have to use mnl_attr_ok() to ensure that the next * attribute is valid. */ -struct nlattr *mnl_attr_next(const struct nlattr *attr, int *len) +struct nlattr *mnl_attr_next(const struct nlattr *attr) { - *len -= MNL_ALIGN(attr->nla_len); return (struct nlattr *)((void *)attr + MNL_ALIGN(attr->nla_len)); } @@ -256,14 +255,11 @@ int mnl_attr_parse(const struct nlmsghdr *nlh, unsigned int offset, mnl_attr_cb_t cb, void *data) { int ret = MNL_CB_OK; - const struct nlattr *attr = mnl_nlmsg_get_payload_offset(nlh, offset); - int len = nlh->nlmsg_len - MNL_NLMSG_HDRLEN - MNL_ALIGN(offset); + const struct nlattr *attr; - while (mnl_attr_ok(attr, len)) { + mnl_attr_for_each(attr, nlh, offset) if ((ret = cb(attr, data)) <= MNL_CB_STOP) return ret; - attr = mnl_attr_next(attr, &len); - } return ret; } @@ -285,14 +281,11 @@ int mnl_attr_parse_nested(const struct nlattr *nested, mnl_attr_cb_t cb, void *data) { int ret = MNL_CB_OK; - const struct nlattr *attr = mnl_attr_get_payload(nested); - int len = mnl_attr_get_payload_len(nested); + const struct nlattr *attr; - while (mnl_attr_ok(attr, len)) { + mnl_attr_for_each_nested(attr, nested) if ((ret = cb(attr, data)) <= MNL_CB_STOP) return ret; - attr = mnl_attr_next(attr, &len); - } return ret; } |