Use assert to validate inputs to allocator functions
This commit is contained in:
		| @@ -1,37 +1,26 @@ | |||||||
| #include "mem_allocator.h" | #include "mem_allocator.h" | ||||||
| #include "../../common/aliases/aliases.h" | #include "../../common/aliases/aliases.h" | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <assert.h> | ||||||
|  |  | ||||||
| void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { | void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) { | ||||||
|   if (!allocator || !(allocator->alloc)) { |   assert(allocator != NULL && (allocator->alloc) != NULL && "allocator argument shouldn't be NULL"); | ||||||
|     return NULL; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   return allocator->alloc(size, allocator->obj); |   return allocator->alloc(size, allocator->obj); | ||||||
| } | } | ||||||
|  |  | ||||||
| void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) { | void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment) { | ||||||
|   if (!allocator || !(allocator->alloc_aligned)) { |   assert(allocator != NULL && (allocator->alloc_aligned) != NULL && "allocator argument shouldn't be NULL"); | ||||||
|     return NULL; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   return allocator->alloc_aligned(size, alignment, allocator->obj); |   return allocator->alloc_aligned(size, alignment, allocator->obj); | ||||||
| } | } | ||||||
|  |  | ||||||
| void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size) { | void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size) { | ||||||
|   if (!allocator || !(allocator->realloc)) { |   assert(allocator != NULL && (allocator->realloc) != NULL && "allocator argument shouldn't be NULL"); | ||||||
|     return NULL; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   return allocator->realloc(ptr, old_size, new_size, allocator->obj); |   return allocator->realloc(ptr, old_size, new_size, allocator->obj); | ||||||
| } | } | ||||||
|  |  | ||||||
| void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size, | void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr, u64 old_size, | ||||||
|                                          u64 new_size, u64 alignment) { |                                          u64 new_size, u64 alignment) { | ||||||
|   if (!allocator || !(allocator->realloc_aligned)) { |   assert(allocator != NULL && (allocator->realloc_aligned) != NULL && "allocator argument shouldn't be NULL"); | ||||||
|     return NULL; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj); |   return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user