From edf2c82cf615af4926cc3536bbbafce2c55fe4e0 Mon Sep 17 00:00:00 2001 From: Jan Matyas Date: Fri, 27 Sep 2024 09:49:52 +0200 Subject: [PATCH] helper/align.h: Fix macro IS_PWR_OF_2 Zero is not a power of two. All functions that use IS_PWR_OF_2 were checked and the edge case of IS_PWR_OF_2(0) does not occur anywhere at the moment. Therefore the fix is safe. Change-Id: I84d9f9c64c9a7df452ca6e99c2ee4169ccb2b0be Signed-off-by: Jan Matyas Fixes: 9544cd653df1 ("helper: add align.h") Reviewed-on: https://review.openocd.org/c/openocd/+/8511 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/helper/align.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/align.h b/src/helper/align.h index 935a6a3b2..d7170065e 100644 --- a/src/helper/align.h +++ b/src/helper/align.h @@ -24,7 +24,7 @@ #define IS_PWR_OF_2(x) \ ({ \ typeof(x) _x = (x); \ - _x == 0 || (_x & (_x - 1)) == 0; \ + _x != 0 && (_x & (_x - 1)) == 0; \ }) #endif /* OPENOCD_HELPER_ALIGN_H */