fix: last block is now right initialise
This commit is contained in:
parent
9d349d1528
commit
15c3f07692
@ -37,8 +37,6 @@ setup_header(ptr, used, size, next_block, prev_block)
|
|||||||
{
|
{
|
||||||
local i;
|
local i;
|
||||||
|
|
||||||
if (size + PADDING_SIZE * 2 + HEADER_SIZE > HEAP_SIZE)
|
|
||||||
return (1);
|
|
||||||
[ptr + LOCATION_INITIALISED] = 1;
|
[ptr + LOCATION_INITIALISED] = 1;
|
||||||
[ptr + LOCATION_USED] = used;
|
[ptr + LOCATION_USED] = used;
|
||||||
[ptr + LOCATION_SIZE] = size;
|
[ptr + LOCATION_SIZE] = size;
|
||||||
@ -67,7 +65,7 @@ find_next_space(size)
|
|||||||
& [current + LOCATION_SIZE] >= size)
|
& [current + LOCATION_SIZE] >= size)
|
||||||
return (current);
|
return (current);
|
||||||
current = [current + LOCATION_NEXT];
|
current = [current + LOCATION_NEXT];
|
||||||
if ([current] == 0)
|
if (current == 0)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +93,10 @@ split_block(ptr, size)
|
|||||||
|
|
||||||
old_size = [ptr + LOCATION_SIZE];
|
old_size = [ptr + LOCATION_SIZE];
|
||||||
if (size + HEADER_SIZE + PADDING_SIZE * 2 > old_size) 🗿 if the block is to small to be split
|
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];
|
old_next = [ptr + LOCATION_NEXT];
|
||||||
next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2;
|
next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2;
|
||||||
prev = [ptr + LOCATION_PREV];
|
prev = [ptr + LOCATION_PREV];
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
name = "galloc";
|
name = "galloc";
|
||||||
test(galloc(1), heap + LOCATION_DATA, "");
|
|
||||||
|
dbg galloc(1);
|
||||||
|
dbg galloc(1);
|
||||||
|
dbg galloc(1);
|
||||||
|
dbg galloc(1);
|
||||||
|
dbg galloc(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user