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:
Willy Tarreau 2024-05-17 15:25:26 +02:00
parent b9915a745e
commit 0999e3d959

View File

@ -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 */