]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
fix: add parenthesis for tests in MIN, MAX and CLAMP macros
authorYann Gautier <yann.gautier@st.com>
Fri, 18 Nov 2022 14:00:43 +0000 (15:00 +0100)
committerYann Gautier <yann.gautier@st.com>
Wed, 7 Dec 2022 13:16:03 +0000 (14:16 +0100)
This corrects the MISRA violation C2012-12.1:
The precedence of operators within expressions should be made explicit

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I62083c43b3f633504cac3497efe2e984924c63b2

include/lib/utils_def.h

index 198b890c7c6b55a5ab80539f5a3b88b5d8c37329..63eda63f615ab09768524501ee08c63be1d518e7 100644 (file)
        __typeof__(x) _x = (x);         \
        __typeof__(y) _y = (y);         \
        (void)(&_x == &_y);             \
-       _x < _y ? _x : _y;              \
+       (_x < _y) ? _x : _y;            \
 })
 
 #define MAX(x, y) __extension__ ({     \
        __typeof__(x) _x = (x);         \
        __typeof__(y) _y = (y);         \
        (void)(&_x == &_y);             \
-       _x > _y ? _x : _y;              \
+       (_x > _y) ? _x : _y;            \
 })
 
 #define CLAMP(x, min, max) __extension__ ({ \
@@ -84,7 +84,7 @@
        __typeof__(max) _max = (max); \
        (void)(&_x == &_min); \
        (void)(&_x == &_max); \
-       (_x > _max ? _max : (_x < _min ? _min : _x)); \
+       ((_x > _max) ? _max : ((_x < _min) ? _min : _x)); \
 })
 
 /*