summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-07-28 09:23:22 (GMT)
committerThomas Haller <thaller@redhat.com>2023-07-28 10:28:24 (GMT)
commit2e0ae977e4d9172fda78dbf0b31b47bd59e7ae3e (patch)
tree7c7f42fbfe02564e6a8a1574516505d3250a9363 /lib
parent57c451fa3f804514b0f97765c2dfdbb58e867df4 (diff)
downloadlibnl-2e0ae977e4d9172fda78dbf0b31b47bd59e7ae3e.zip
libnl-2e0ae977e4d9172fda78dbf0b31b47bd59e7ae3e.tar.gz
libnl-2e0ae977e4d9172fda78dbf0b31b47bd59e7ae3e.tar.bz2
all: use _NL_{MIN,MAX}() macros
Replace the use of the previous min()/min_t()/max()/max_t(). - min_t()/max_t() required a type, and would do plain assignment, which C would not complain about. It is thus a cumbersome and not very safe pattern. Avoid it. - min()/max() did better, it used typeof() to preserve the argument types and automatically detect it. However, it also required that both arguments had the same integer type, which is unnecessarily strict. _NL_MIN()/_NL_MAX() does better. It accepts arguments of any integer types, but has a static assertions that they match in signedness. So it's more flexible to use than min()/max() and still quite safe. Prefer the new macros.
Diffstat (limited to 'lib')
-rw-r--r--lib/addr.c2
-rw-r--r--lib/attr.c2
-rw-r--r--lib/msg.c2
-rw-r--r--lib/route/cls/ematch_syntax.y2
-rw-r--r--lib/route/link/inet.c2
-rw-r--r--lib/route/link/inet6.c6
6 files changed, 8 insertions, 8 deletions
diff --git a/lib/addr.c b/lib/addr.c
index d0b5f33..6ca3bae 100644
--- a/lib/addr.c
+++ b/lib/addr.c
@@ -625,7 +625,7 @@ int nl_addr_cmp_prefix(const struct nl_addr *a, const struct nl_addr *b)
int d = a->a_family - b->a_family;
if (d == 0) {
- int len = min(a->a_prefixlen, b->a_prefixlen);
+ int len = _NL_MIN(a->a_prefixlen, b->a_prefixlen);
int bytes = len / 8;
d = memcmp(a->a_addr, b->a_addr, bytes);
diff --git a/lib/attr.c b/lib/attr.c
index a8913d3..d919811 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -350,7 +350,7 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count)
if (!src)
return 0;
- minlen = min_t(int, count, nla_len(src));
+ minlen = _NL_MIN(count, nla_len(src));
memcpy(dest, nla_data(src), minlen);
return minlen;
diff --git a/lib/msg.c b/lib/msg.c
index 17ca812..0e64722 100644
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -148,7 +148,7 @@ struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh, int hdrlen)
*/
int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
{
- return max_t(int, nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
+ return _NL_MAX(nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0u);
}
/** @} */
diff --git a/lib/route/cls/ematch_syntax.y b/lib/route/cls/ematch_syntax.y
index 0c89603..0832a6e 100644
--- a/lib/route/cls/ematch_syntax.y
+++ b/lib/route/cls/ematch_syntax.y
@@ -406,7 +406,7 @@ pattern:
if (nl_addr_parse($1, AF_UNSPEC, &addr) == 0) {
$$.len = nl_addr_get_len(addr);
- $$.index = min_t(int, $$.len, nl_addr_get_prefixlen(addr)/8);
+ $$.index = _NL_MIN($$.len, nl_addr_get_prefixlen(addr)/8);
if (!($$.data = calloc(1, $$.len))) {
nl_addr_put(addr);
diff --git a/lib/route/link/inet.c b/lib/route/link/inet.c
index 2f95fb6..b4a520a 100644
--- a/lib/route/link/inet.c
+++ b/lib/route/link/inet.c
@@ -104,7 +104,7 @@ static int inet_parse_af(struct rtnl_link *link, struct nlattr *attr, void *data
if (tb[IFLA_INET_CONF]) {
int i;
- int len = min_t(int, IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
+ int len = _NL_MIN(IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
for (i = 0; i < len; i++)
id->i_confset[i] = 1;
diff --git a/lib/route/link/inet6.c b/lib/route/link/inet6.c
index 08b29a8..e8310b3 100644
--- a/lib/route/link/inet6.c
+++ b/lib/route/link/inet6.c
@@ -167,7 +167,7 @@ static int inet6_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
sizeof(i6->i6_cacheinfo));
if (tb[IFLA_INET6_CONF]) {
- i6->i6_conf_len = min(ARRAY_SIZE(i6->i6_conf),
+ i6->i6_conf_len = _NL_MIN(ARRAY_SIZE(i6->i6_conf),
nla_len(tb[IFLA_INET6_CONF]) /
sizeof(i6->i6_conf[0]));
nla_memcpy(&i6->i6_conf, tb[IFLA_INET6_CONF],
@@ -202,7 +202,7 @@ static int inet6_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
map_stat_id = map_stat_id_from_IPSTATS_MIB_v1;
}
- len = min_t(int, __IPSTATS_MIB_MAX, len);
+ len = _NL_MIN(__IPSTATS_MIB_MAX, len);
for (i = 1; i < len; i++) {
memcpy(&stat, &cnt[i * sizeof(stat)], sizeof(stat));
rtnl_link_set_stat(link, map_stat_id[i], stat);
@@ -213,7 +213,7 @@ static int inet6_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
unsigned char *cnt = nla_data(tb[IFLA_INET6_ICMP6STATS]);
uint64_t stat;
int i;
- int len = min_t(int, __ICMP6_MIB_MAX, nla_len(tb[IFLA_INET6_ICMP6STATS]) / 8);
+ int len = _NL_MIN(__ICMP6_MIB_MAX, nla_len(tb[IFLA_INET6_ICMP6STATS]) / 8);
_NL_STATIC_ASSERT (__ICMP6_MIB_MAX == 6);
_NL_STATIC_ASSERT (RTNL_LINK_ICMP6_CSUMERRORS - RTNL_LINK_ICMP6_INMSGS + 1 == 5);