include: zephyr: sys: util: Add type check for macro DIV_ROUND_CLOSEST

Add type check to avoid comparing unsigned values with 0 which is always
true or false and can cause coverity issue.

Signed-off-by: Trung Hieu Le <trunghieu.le@nxp.com>
This commit is contained in:
Trung Hieu Le 2024-11-27 17:21:17 +01:00 committed by Anas Nashif
commit 64ce567f5d

View file

@ -366,9 +366,10 @@ extern "C" {
*
* @return The result of @p n / @p d, rounded to the nearest integer.
*/
#define DIV_ROUND_CLOSEST(n, d) \
((((n) < 0) ^ ((d) < 0)) ? ((n) - ((d) / 2)) / (d) : \
((n) + ((d) / 2)) / (d))
#define DIV_ROUND_CLOSEST(n, d) \
(((((__typeof__(n))-1) < 0) && (((__typeof__(d))-1) < 0) && ((n) < 0) ^ ((d) < 0)) \
? ((n) - ((d) / 2)) / (d) \
: ((n) + ((d) / 2)) / (d))
#ifndef MAX
/**