diff options
| author | 安静的卡尔 <silentcarl1990@gmail.com> | 2019-01-10 16:24:33 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-10 16:24:33 +0800 |
| commit | 2181fcf369c54540b005e90ee45628b1e0bdf60d (patch) | |
| tree | c22c6276521b110ea78c14bc5c6068d9469ce824 /tinyalloc.c | |
| parent | 8feeb53d0f54969126bee001ade15b0ea9f7eb8d (diff) | |
out of bouds
Diffstat (limited to 'tinyalloc.c')
| -rw-r--r-- | tinyalloc.c | 3 |
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; |
