From 15c3f07692cfe084113836b614c17c9791aeff2e Mon Sep 17 00:00:00 2001 From: starnakin Date: Sat, 17 Jun 2023 00:31:27 +0200 Subject: [PATCH] fix: last block is now right initialise --- src/galloc.🗿 | 9 +++++---- tests/galloc.🗿 | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/galloc.🗿 b/src/galloc.🗿 index 5045173..9e7bca5 100644 --- a/src/galloc.🗿 +++ b/src/galloc.🗿 @@ -37,8 +37,6 @@ setup_header(ptr, used, size, next_block, prev_block) { local i; - if (size + PADDING_SIZE * 2 + HEADER_SIZE > HEAP_SIZE) - return (1); [ptr + LOCATION_INITIALISED] = 1; [ptr + LOCATION_USED] = used; [ptr + LOCATION_SIZE] = size; @@ -67,7 +65,7 @@ find_next_space(size) & [current + LOCATION_SIZE] >= size) return (current); current = [current + LOCATION_NEXT]; - if ([current] == 0) + if (current == 0) return (0); } } @@ -95,7 +93,10 @@ split_block(ptr, size) old_size = [ptr + LOCATION_SIZE]; if (size + HEADER_SIZE + PADDING_SIZE * 2 > old_size) 🗿 if the block is to small to be split - return (0); + { + [ptr + LOCATION_USED] = 1; + return (ptr); + } old_next = [ptr + LOCATION_NEXT]; next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2; prev = [ptr + LOCATION_PREV]; diff --git a/tests/galloc.🗿 b/tests/galloc.🗿 index fb9d6ee..f0cf94d 100644 --- a/tests/galloc.🗿 +++ b/tests/galloc.🗿 @@ -1,5 +1,10 @@ main() { name = "galloc"; - test(galloc(1), heap + LOCATION_DATA, ""); + + dbg galloc(1); + dbg galloc(1); + dbg galloc(1); + dbg galloc(1); + dbg galloc(1); }