mirror of https://github.com/thesofproject/sof.git
math: replace MIN() and MAX() macros with safer versions
Using macro arguments multiple times within the macro definition body can lead to repeated expressioon evaluation. To avoid that replace MIN() and MAX() macros with safer versions. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
parent
a06d4b1c2c
commit
1f79acd74c
|
@ -35,8 +35,16 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) ({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
__a > __b ? __b : __a; \
|
||||
})
|
||||
#define MAX(a, b) ({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
__a < __b ? __b : __a; \
|
||||
})
|
||||
|
||||
int gcd(int a, int b); /* Calculate greatest common divisor for a and b */
|
||||
|
||||
|
|
Loading…
Reference in New Issue