Commit d1f8e1f8 authored by Yanir Levin's avatar Yanir Levin Committed by Benjamin Cabé
Browse files

include: sys: util: Fix LOG2CEIL macro

LOG2CEIL(1) results in undefined behaviour,
as LOG2CEIL(1) expands to __builtin_clz(0),
which is undefined according to GCC docs.

Signed-off-by: default avatarYanir Levin <yanir10@gmail.com>
parent 3d68d054
Loading
Loading
Loading
Loading
+1 −1
Changes for include/zephyr/sys/util.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -712,7 +712,7 @@ char *utf8_lcpy(char *dst, const char *src, size_t n);
 *
 * @return ceil(log2(x)) when 1 <= x <= max(type(x)), 0 when x < 1
 */
#define LOG2CEIL(x) ((x) < 1 ?  0 : __z_log2((x)-1) + 1)
#define LOG2CEIL(x) ((x) <= 1 ?  0 : __z_log2((x)-1) + 1)

/**
 * @brief Compute next highest power of two