mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-09 16:42:40 +02:00
CLEANUP: compat: make the MIN/MAX macros more reliable
After every release we say that MIN/MAX should be changed to be an expression that only evaluates each operand once, and before every version we forget to change it and we recheck that the code doesn't misuse them. Let's fix them now.
This commit is contained in:
@@ -94,11 +94,19 @@ typedef struct { } empty_t;
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MIN(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(a) _b = (b); \
|
||||
((_a < _b) ? _a : _b); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MAX(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(a) _b = (b); \
|
||||
((_a > _b) ? _a : _b); \
|
||||
})
|
||||
#endif
|
||||
|
||||
/* this is for libc5 for example */
|
||||
|
||||
Reference in New Issue
Block a user