From a169fe36547c6d91e8726f9d8643de7a87bd3c35 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 24 Feb 2024 20:26:37 +0000 Subject: [PATCH] Return NULL when aligning forward if ptr is NULL --- mem/src/util/mem_utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mem/src/util/mem_utils.c b/mem/src/util/mem_utils.c index 89ae685..58d8ae3 100644 --- a/mem/src/util/mem_utils.c +++ b/mem/src/util/mem_utils.c @@ -2,10 +2,15 @@ #include "aliases.h" #include #include +#include internal bool is_power_of_two(u64 num) { return (num & (num - 1)) == 0; } void *mem_util_align_forward(void *ptr, u64 alignment) { + if (!ptr) { + return NULL; + } + assert(is_power_of_two(alignment)); uptr p = (uptr)ptr;