]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: fix MIN/MAX macros to not double-eval
authorDavid Lamparter <equinox@opensourcerouting.org>
Sat, 12 Mar 2016 18:58:09 +0000 (19:58 +0100)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 17 Mar 2016 23:52:10 +0000 (19:52 -0400)
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>
lib/zebra.h

index f49db41d267cdf1480b2b54b87ca02e458ce5902..8cef0bfac2d3afbfe62b75c228fa30719e6acf0c 100644 (file)
@@ -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]))