Skip to content

Commit 8406db1

Browse files
committed
fix: add parenthesis for tests in MIN, MAX and CLAMP macros
This corrects the MISRA violation C2012-12.1: The precedence of operators within expressions should be made explicit Signed-off-by: Yann Gautier <[email protected]> Change-Id: I62083c43b3f633504cac3497efe2e984924c63b2
1 parent 825641d commit 8406db1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/lib/utils_def.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@
6868
__typeof__(x) _x = (x); \
6969
__typeof__(y) _y = (y); \
7070
(void)(&_x == &_y); \
71-
_x < _y ? _x : _y; \
71+
(_x < _y) ? _x : _y; \
7272
})
7373

7474
#define MAX(x, y) __extension__ ({ \
7575
__typeof__(x) _x = (x); \
7676
__typeof__(y) _y = (y); \
7777
(void)(&_x == &_y); \
78-
_x > _y ? _x : _y; \
78+
(_x > _y) ? _x : _y; \
7979
})
8080

8181
#define CLAMP(x, min, max) __extension__ ({ \
@@ -84,7 +84,7 @@
8484
__typeof__(max) _max = (max); \
8585
(void)(&_x == &_min); \
8686
(void)(&_x == &_max); \
87-
(_x > _max ? _max : (_x < _min ? _min : _x)); \
87+
((_x > _max) ? _max : ((_x < _min) ? _min : _x)); \
8888
})
8989

9090
/*

0 commit comments

Comments
 (0)