aboutsummaryrefslogtreecommitdiff
path: root/tinyalloc.c
diff options
context:
space:
mode:
authorKarsten Schmidt <info@postspectacular.com>2019-01-10 11:21:29 +0000
committerGitHub <noreply@github.com>2019-01-10 11:21:29 +0000
commit9ebd4a406bf783a68b0e0ba57545f11f12bf5827 (patch)
treec22c6276521b110ea78c14bc5c6068d9469ce824 /tinyalloc.c
parent8feeb53d0f54969126bee001ade15b0ea9f7eb8d (diff)
parent2181fcf369c54540b005e90ee45628b1e0bdf60d (diff)
Merge pull request #3 from silentcarl/master
out of bouds
Diffstat (limited to 'tinyalloc.c')
-rw-r--r--tinyalloc.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tinyalloc.c b/tinyalloc.c
index 9b07461..066fecc 100644
--- a/tinyalloc.c
+++ b/tinyalloc.c
@@ -143,6 +143,7 @@ bool ta_init() {
block->next = block + 1;
block++;
}
+ block->next = NULL;
return true;
}
@@ -174,7 +175,7 @@ static Block *alloc_block(size_t num) {
size_t top = heap->top;
num = (num + TA_ALIGN - 1) & -TA_ALIGN;
while (ptr != NULL) {
- const int is_top = (size_t)ptr->addr + ptr->size >= top;
+ const int is_top = ((size_t)ptr->addr + ptr->size >= top) && ((size_t)ptr->addr + num <= TA_HEAP_LIMIT);
if (is_top || ptr->size >= num) {
if (prev != NULL) {
prev->next = ptr->next;