about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-04-16 15:42:45 +0200
committerptitSeb <sebastien.chev@gmail.com>2021-04-16 15:42:45 +0200
commit08d2ac41f65e15144e98272e91bb070ff8946d0e (patch)
tree3eb0732e470552e356a955ddc0529ef000053c27
parentfd939c6fce61627137cb184c8eaad618f68efdf5 (diff)
downloadbox64-08d2ac41f65e15144e98272e91bb070ff8946d0e.tar.gz
box64-08d2ac41f65e15144e98272e91bb070ff8946d0e.zip
Some improvement to custommem handling
-rw-r--r--src/custommem.c8
1 files changed, 4 insertions, 4 deletions
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...
         }