master hovercats/oakiss / pkg / libnl / patch / 0001-Use-static-inline-functions-for-min-and-max.patch
  1From 5205a990e10f9bf1102c719198f82aba342cbca5 Mon Sep 17 00:00:00 2001
  2From: Michael Forney <mforney@mforney.org>
  3Date: Sun, 11 Aug 2019 05:05:09 +0000
  4Subject: [PATCH] Use static inline functions for min and max
  5
  6These generic macros were only ever used with type `int`, and making
  7them inline functions avoids the use of non-standard statement
  8expressions.
  9---
 10 include/netlink-private/netlink.h | 27 +++++++++++----------------
 11 lib/attr.c                        |  2 +-
 12 lib/msg.c                         |  2 +-
 13 lib/route/cls/ematch_syntax.y     |  2 +-
 14 lib/route/link/inet.c             |  2 +-
 15 lib/route/link/inet6.c            |  2 +-
 16 6 files changed, 16 insertions(+), 21 deletions(-)
 17
 18diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
 19index 5f6e3f7..fca3133 100644
 20--- a/include/netlink-private/netlink.h
 21+++ b/include/netlink-private/netlink.h
 22@@ -158,22 +158,17 @@ static inline int nl_cb_call(struct nl_cb *cb, enum nl_cb_type type, struct nl_m
 23 #undef __deprecated
 24 #define __deprecated __attribute__ ((deprecated))
 25 
 26-#define min(x,y) ({ \
 27-	__typeof__(x) _x = (x);	\
 28-	__typeof__(y) _y = (y);	\
 29-	(void) (&_x == &_y);		\
 30-	_x < _y ? _x : _y; })
 31-
 32-#define max(x,y) ({ \
 33-	__typeof__(x) _x = (x);	\
 34-	__typeof__(y) _y = (y);	\
 35-	(void) (&_x == &_y);		\
 36-	_x > _y ? _x : _y; })
 37-
 38-#define min_t(type,x,y) \
 39-	({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
 40-#define max_t(type,x,y) \
 41-	({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
 42+static inline int
 43+min(int x, int y)
 44+{
 45+	return x < y ? x : y;
 46+}
 47+
 48+static inline int
 49+max(int x, int y)
 50+{
 51+	return x > y ? x : y;
 52+}
 53 
 54 extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
 55 			  struct nlmsghdr *, struct nl_parser_param *);
 56diff --git a/lib/attr.c b/lib/attr.c
 57index a4f5852..025627e 100644
 58--- a/lib/attr.c
 59+++ b/lib/attr.c
 60@@ -358,7 +358,7 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count)
 61 	if (!src)
 62 		return 0;
 63 	
 64-	minlen = min_t(int, count, nla_len(src));
 65+	minlen = min(count, nla_len(src));
 66 	memcpy(dest, nla_data(src), minlen);
 67 
 68 	return minlen;
 69diff --git a/lib/msg.c b/lib/msg.c
 70index c08b3a4..d854df3 100644
 71--- a/lib/msg.c
 72+++ b/lib/msg.c
 73@@ -155,7 +155,7 @@ struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh, int hdrlen)
 74  */
 75 int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
 76 {
 77-	return max_t(int, nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
 78+	return max(nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
 79 }
 80 
 81 /** @} */
 82diff --git a/lib/route/cls/ematch_syntax.y b/lib/route/cls/ematch_syntax.y
 83index 82d753d..88665cc 100644
 84--- a/lib/route/cls/ematch_syntax.y
 85+++ b/lib/route/cls/ematch_syntax.y
 86@@ -411,7 +411,7 @@ pattern:
 87 			if (nl_addr_parse($1, AF_UNSPEC, &addr) == 0) {
 88 				$$.len = nl_addr_get_len(addr);
 89 
 90-				$$.index = min_t(int, $$.len, nl_addr_get_prefixlen(addr)/8);
 91+				$$.index = min($$.len, nl_addr_get_prefixlen(addr)/8);
 92 
 93 				if (!($$.data = calloc(1, $$.len))) {
 94 					nl_addr_put(addr);
 95diff --git a/lib/route/link/inet.c b/lib/route/link/inet.c
 96index 6651bc3..e33a3fe 100644
 97--- a/lib/route/link/inet.c
 98+++ b/lib/route/link/inet.c
 99@@ -110,7 +110,7 @@ static int inet_parse_af(struct rtnl_link *link, struct nlattr *attr, void *data
100 
101 	if (tb[IFLA_INET_CONF]) {
102 		int i;
103-		int len = min_t(int, IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
104+		int len = min(IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
105 
106 		for (i = 0; i < len; i++)
107 			id->i_confset[i] = 1;
108diff --git a/lib/route/link/inet6.c b/lib/route/link/inet6.c
109index f02792c..8a3de01 100644
110--- a/lib/route/link/inet6.c
111+++ b/lib/route/link/inet6.c
112@@ -199,7 +199,7 @@ static int inet6_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
113 			map_stat_id = map_stat_id_from_IPSTATS_MIB_v1;
114 		}
115 
116-		len = min_t(int, __IPSTATS_MIB_MAX, len);
117+		len = min(__IPSTATS_MIB_MAX, len);
118 		for (i = 1; i < len; i++) {
119 			memcpy(&stat, &cnt[i * sizeof(stat)], sizeof(stat));
120 			rtnl_link_set_stat(link, map_stat_id[i], stat);
121-- 
1222.23.0
123