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>
diff --git a/lib/zebra.h b/lib/zebra.h
index d980283..0ea5ee4 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -373,10 +373,16 @@
/* 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]))