From 5431fec6726c18234c9c28b014cc6f18a0d79884 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Fri, 6 Jun 2025 14:09:32 -0500 Subject: Style touchup --- src/arena.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/arena.c') diff --git a/src/arena.c b/src/arena.c index 40c72d5..8f32064 100644 --- a/src/arena.c +++ b/src/arena.c @@ -1,6 +1,7 @@ #include "arena.h" #include "shared.h" +#include #include #include #include @@ -26,6 +27,8 @@ typedef struct arena { } arena; arenanode * arenanode_init(size_t bytes) { + if(bytes < 1) ERRRET(EINVAL, NULL); + arenanode *an = VALLOC(1, sizeof(*an)); if(!an) return NULL; @@ -47,10 +50,8 @@ arenanode * arenanode_init(size_t bytes) { } arena * arena_init(size_t bytes) { - if(!ISPOWOF2(MEM_ALIGN_BYTES)) - XALLOC_EXIT(" \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to create a new arena", ); - if(bytes < 1) - RETURNWERR(EINVAL, NULL); + if(!ISPOWOF2(MEM_ALIGN_BYTES)) XALLOC_EXIT(" \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to create a new arena", ); + if(bytes < 1) ERRRET(EINVAL, NULL); arena *a = VALLOC(1, sizeof(arena)); if(!a) @@ -73,12 +74,9 @@ arena * arena_init(size_t bytes) { } void * arena_alloc(arena * const arena, size_t bytes) { - if(!ISPOWOF2(MEM_ALIGN_BYTES)) - XALLOC_EXIT(" \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to allocate any memory", ); - if(!arena) - RETURNWERR(EINVAL, NULL); - if(bytes > arena->node_memspace) - RETURNWERR(ENOMEM, NULL); + if(!ISPOWOF2(MEM_ALIGN_BYTES)) XALLOC_EXIT(" \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to allocate any memory", ); + if(!arena) ERRRET(EINVAL, NULL); + if(bytes > arena->node_memspace) ERRRET(ENOMEM, NULL); if(bytes > ((arena->current)->allocated - (arena->current)->used)) { arenanode *new = arenanode_init(arena->node_memspace); @@ -133,10 +131,8 @@ void * simplearena_alloc(simplearena * const a, size_t bytes) { // The criteria to allocate new memory in arena_alloc is 'bytes > ((a->current)->allocated - (a->current)->used)', so if this // is true, just return NULL & set errno - if(!a) - RETURNWERR(EINVAL, NULL); - if(bytes > ((a->current)->allocated - (a->current)->used)) - RETURNWERR(ENOMEM, NULL); + if(!a) ERRRET(EINVAL, NULL); + if(bytes > ((a->current)->allocated - (a->current)->used)) ERRRET(ENOMEM, NULL); return arena_alloc(a, bytes); } -- cgit v1.2.3