pool: guard against overflow

This commit is contained in:
2026-08-04 01:11:52 +02:00
parent 98f08084b5
commit 426534e066
+4 -1
View File
@@ -19,7 +19,8 @@ APool *apool_create_ex(Allocator *allocator, U32 n_elements, U32 element_size, U
pool->start = NULL;
if (size != APOOL_AUTOGROW) {
U32 total_size = n_elements * size; // Note(nos): guard against unreasonable sizes
Assert(n_elements <= U32_Max / size );
U32 total_size = n_elements * size;
U8 * start = allocator_push(allocator, total_size, align);
for (U32 i = 0; i < total_size; i += size) {
APoolElement *element = (APoolElement *)&start[i];
@@ -47,6 +48,8 @@ void *apool_alloc(APool *pool)
void apool_free(APool *pool, void *ptr)
{
if (ptr != NULL) {
Assert((U8 *)ptr >= pool->start);
APoolElement *element = (APoolElement *)ptr;
element->next = pool->free_list;
pool->free_list = element;