From 8e952d9bc8c83e6f762ca895453ecd2bf509ece4 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Mon, 5 May 2025 19:01:10 +0100 Subject: [PATCH] Use assert to validate inputs to allocator functions --- src/primitives/mem_allocator/mem_allocator.c | 21 +++++--------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/primitives/mem_allocator/mem_allocator.c b/src/primitives/mem_allocator/mem_allocator.c index 36a10ab..762a07b 100644 --- a/src/primitives/mem_allocator/mem_allocator.c +++ b/src/primitives/mem_allocator/mem_allocator.c @@ -1,37 +1,26 @@ #include "mem_allocator.h" #include "../../common/aliases/aliases.h" #include +#include void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { - if (!allocator || !(allocator->alloc)) { - return NULL; - } - + assert(allocator != NULL && (allocator->alloc) != NULL && "allocator argument shouldn't be NULL"); return allocator->alloc(size, allocator->obj); } void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) { - if (!allocator || !(allocator->alloc_aligned)) { - return NULL; - } - + assert(allocator != NULL && (allocator->alloc_aligned) != NULL && "allocator argument shouldn't be NULL"); return allocator->alloc_aligned(size, alignment, allocator->obj); } void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size) { - if (!allocator || !(allocator->realloc)) { - return NULL; - } - + assert(allocator != NULL && (allocator->realloc) != NULL && "allocator argument shouldn't be NULL"); return allocator->realloc(ptr, old_size, new_size, allocator->obj); } void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size, u64 alignment) { - if (!allocator || !(allocator->realloc_aligned)) { - return NULL; - } - + assert(allocator != NULL && (allocator->realloc_aligned) != NULL && "allocator argument shouldn't be NULL"); return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj); }