Skip to contentSkip to conversation

include: libmnl.h: Add explicit casts to macros for C++

PATCH In review Phil Sutter 2 participants 3 messages Nov 11 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 include: libmnl.h: Add explicit casts to macros for C++

C++ does not like implicit casts of void pointers, make them explicit there. After adjusting similar cases in example source files, these are the only needed header adjustments needed to compile them with g++.

---
 include/libmnl/libmnl.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/libmnl/libmnl.h +2 -2
index 9c032807097f7..2c18e50e6026d 100644
@@ -146,12 +146,12 @@ extern bool mnl_attr_ok(const struct nlattr *attr, int len);
 extern 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)); \
+	for ((attr) = (struct nlattr *)mnl_nlmsg_get_payload_offset((nlh), (offset)); \
 	     mnl_attr_ok((attr), (char *)mnl_nlmsg_get_payload_tail(nlh) - (char *)(attr)); \
 	     (attr) = mnl_attr_next(attr))
 
 #define mnl_attr_for_each_nested(attr, nest) \
-	for ((attr) = mnl_attr_get_payload(nest); \
+	for ((attr) = (struct nlattr *)mnl_attr_get_payload(nest); \
 	     mnl_attr_ok((attr), (char *)mnl_attr_get_payload(nest) + mnl_attr_get_payload_len(nest) - (char *)(attr)); \
 	     (attr) = mnl_attr_next(attr))
 
Signature · 1 line
2.54.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Phil Sutter

C++ does not like implicit casts of void pointers, make them explicit there. After adjusting similar cases in example source files, these are the only needed header adjustments needed to compile them with g++.

author reviewer
#2 lore raw
Quoted 6 lines · Florian Westphal
Quoted 3 lines · Phil Sutter

C++ does not like implicit casts of void pointers, make them explicit there. After adjusting similar cases in example source files, these are the only needed header adjustments needed to compile them with g++.

Applied after dropping the redundant "needed" up there. Thanks for your review!