From a74979ff72d7ab86faf463c509591f5c2e080ce9 Mon Sep 17 00:00:00 2001 From: fishpepper Date: Tue, 15 Aug 2017 21:07:14 +0200 Subject: [PATCH] fix dangerous MIN/MAX/ABS definitions --- src/main/common/maths.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/common/maths.h b/src/main/common/maths.h index 5a0bdcb596..fea305032b 100644 --- a/src/main/common/maths.h +++ b/src/main/common/maths.h @@ -37,9 +37,17 @@ #define CM_S_TO_KM_H(centimetersPerSecond) (centimetersPerSecond * 36 / 1000) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define ABS(x) ((x) > 0 ? (x) : -(x)) +#define MIN(a,b) \ + __extension__ ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) +#define MAX(a,b) \ + __extension__ ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a > _b ? _a : _b; }) +#define ABS(x) \ + __extension__ ({ __typeof__ (x) _x = (x); \ + _x > 0 ? _x : -_x; }) #define Q12 (1 << 12)