From c3555431d4420701d66618bf4d7d6f9f684f8e8e Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sat, 13 Feb 2021 19:53:30 -0400 Subject: [PATCH] Prevent ALIGN_DOWN() from overflowing. --- source/utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/utils.h b/source/utils.h index 75cd6b2..25748e7 100644 --- a/source/utils.h +++ b/source/utils.h @@ -53,8 +53,8 @@ #define BIT_LONG(n) (1UL << (n)) -#define ALIGN_UP(x, y) ((((y) - 1) + (x)) & ~((y) - 1)) -#define ALIGN_DOWN(x, y) (((x) - ((y) - 1)) & ~((y) - 1)) +#define ALIGN_UP(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) +#define ALIGN_DOWN(x, y) ((x) > (y) ? (((x) - ((y) - 1)) & ~((y) - 1)) : 0) #define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0) #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)