From c9c047dcc6d21b98144fb15f654e4d8f4f10f2de Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 3 Oct 2014 20:22:18 +0100 Subject: [PATCH] util.h etc.: Provide MAX_RAW and MIN_RAW; etc. MAX and MIN are unsuitable for use where a constant expression is required. Provide MAX_RAW and MIN_RAW which are suitable but might evaluate the left argument twice. Remove max() in ipaddr.c and replace the call with one to MAX (not MAX_RAW. (The old max macro there is operator-priority-unsafe but there is only one call site and it happens to be OK.) We ae going to use MAX_RAW later. No functional change. Signed-off-by: Ian Jackson --- ipaddr.c | 4 ++-- util.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ipaddr.c b/ipaddr.c index e6d2407..899581f 100644 --- a/ipaddr.c +++ b/ipaddr.c @@ -7,6 +7,7 @@ #include #include #include "ipaddr.h" +#include "util.h" #define DEFAULT_ALLOC 2 #define EXTEND_ALLOC_BY 4 @@ -130,7 +131,6 @@ static void ipset_append_range(struct ipset *a, struct iprange r) a->d[a->l-1]=r; } -#define max(a,b) (a>b?a:b) struct ipset *ipset_union(struct ipset *a, struct ipset *b) { struct ipset *c; @@ -155,7 +155,7 @@ struct ipset *ipset_union(struct ipset *a, struct ipset *b) ipset_append_range(c,r); else if (r.a <= c->d[c->l-1].b+1) /* Extends (or is consumed by) the last range */ - c->d[c->l-1].b=max(c->d[c->l-1].b, r.b); + c->d[c->l-1].b=MAX(c->d[c->l-1].b, r.b); else ipset_append_range(c,r); } diff --git a/util.h b/util.h index b44b911..a5a82a4 100644 --- a/util.h +++ b/util.h @@ -161,6 +161,9 @@ async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf, #define MAX(a,b) MINMAX((a),(b),>) #define MIN(a,b) MINMAX((a),(b),<) +#define MAX_RAW(a,b) ((a)>(b)?(a):(b)) +#define MIN_RAW(a,b) ((a)<(b)?(a):(b)) + static inline bool_t iswouldblock(int e) { return e==EWOULDBLOCK || e==EAGAIN; } -- 2.30.2