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 /include/libmnl | |
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 'include/libmnl')
-rw-r--r-- | include/libmnl/libmnl.h | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h index a194185..c58635f 100644 --- a/include/libmnl/libmnl.h +++ b/include/libmnl/libmnl.h @@ -128,19 +128,17 @@ MNL_API int mnl_attr_validate2(const struct nlattr *attr, enum mnl_attr_data_typ /* TLV iterators */ MNL_API bool mnl_attr_ok(const struct nlattr *attr, int len); -MNL_API struct nlattr *mnl_attr_next(const struct nlattr *attr, int *len); - -#define mnl_attr_for_each(attr, nlh, offset) \ - int __len__ = mnl_nlmsg_get_payload_len(nlh); \ - for (attr = mnl_nlmsg_get_payload_offset(nlh, offset); \ - mnl_attr_ok(attr, __len__); \ - attr = mnl_attr_next(attr, &(__len__))) - -#define mnl_attr_for_each_nested(attr, nest) \ - int __len__ = mnl_attr_get_len(nest); \ - for (attr = mnl_attr_get_payload(nest); \ - mnl_attr_ok(attr, __len__); \ - attr = mnl_attr_next(attr, &(__len__))) +MNL_API struct nlattr *mnl_attr_next(const struct nlattr *attr); + +#define mnl_attr_for_each(attr, nlh, offset) \ + for ((attr) = mnl_nlmsg_get_payload_offset((nlh), (offset)); \ + mnl_attr_ok((attr), mnl_nlmsg_get_payload_tail(nlh) - (void *)(attr)); \ + (attr) = mnl_attr_next(attr)) + +#define mnl_attr_for_each_nested(attr, nest) \ + for ((attr) = mnl_attr_get_payload(nest); \ + mnl_attr_ok((attr), mnl_attr_get_payload(nest) + mnl_attr_get_payload_len(nest) - (void *)(attr)); \ + (attr) = mnl_attr_next(attr)) /* TLV callback-based attribute parsers */ typedef int (*mnl_attr_cb_t)(const struct nlattr *attr, void *data); |