From 08d2ac41f65e15144e98272e91bb070ff8946d0e Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Fri, 16 Apr 2021 15:42:45 +0200 Subject: Some improvement to custommem handling --- src/custommem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/custommem.c b/src/custommem.c index a4c4a00d..7f176fa3 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -73,14 +73,14 @@ typedef struct blockmark_s { } blockmark_t; -// get first subblock free in block, stating at start (from block). return NULL if no block, else first subblock free (mark included), filling size +// get first subblock free in block. Return NULL if no block, else first subblock free (mark included), filling size static void* getFirstBlock(void* block, size_t maxsize, size_t* size) { // get start of block blockmark_t *m = (blockmark_t*)block; while(m->next.x32) { // while there is a subblock if(!m->next.fill && m->next.size>=maxsize+sizeof(blockmark_t)) { - *size = m->next.size; + *size = m->next.size-sizeof(blockmark_t); return m; } m = (blockmark_t*)((uintptr_t)m + m->next.size); @@ -92,11 +92,11 @@ static void* getFirstBlock(void* block, size_t maxsize, size_t* size) static size_t getMaxFreeBlock(void* block, size_t block_size) { // get start of block - blockmark_t *m = (blockmark_t*)((uintptr_t)block+block_size-sizeof(blockmark_t)); // styart with the end + blockmark_t *m = (blockmark_t*)((uintptr_t)block+block_size-sizeof(blockmark_t)); // start with the end int maxsize = 0; while(m->prev.x32) { // while there is a subblock if(!m->prev.fill && m->prev.size>maxsize) { - maxsize = m->prev.size; + maxsize = m->prev.size-sizeof(blockmark_t); if((uintptr_t)block+maxsize>(uintptr_t)m) return maxsize; // no block large enough left... } -- cgit 1.4.1