diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2016-03-12 19:58:09 +0100 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-03-18 00:52:10 +0100 |
commit | 8a0bebfc3a0edc5e32b2aa3785d3d8367504a393 (patch) | |
tree | 9dc7330fb8bdbe2a6433cee64a33dd59bc2b5c43 /lib/zebra.h | |
parent | Fixes Quagga Bugzilla #842 - ospfd uses non-zero metric when describing loopb... (diff) | |
download | frr-8a0bebfc3a0edc5e32b2aa3785d3d8367504a393.tar.xz frr-8a0bebfc3a0edc5e32b2aa3785d3d8367504a393.zip |
lib: fix MIN/MAX macros to not double-eval
cf. https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
(Works on all compilers on Quagga's compiler support list in
doc/overview.texi)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Tested-by: NetDEF CI System <cisystem@netdef.org>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib/zebra.h')
-rw-r--r-- | lib/zebra.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/zebra.h b/lib/zebra.h index f49db41d2..8cef0bfac 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -384,10 +384,16 @@ struct in_pktinfo /* MAX / MIN are not commonly defined, but useful */ #ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif +#define MAX(a, b) \ + ({ typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a > _b ? _a : _b; }) +#endif #ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MIN(a, b) \ + ({ typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a < _b ? _a : _b; }) #endif #define ZEBRA_NUM_OF(x) (sizeof (x) / sizeof (x[0])) |