Prevent a few edge case overflows
This commit is contained in:
+2
-2
@@ -60,10 +60,10 @@ void *arena_push(Arena *arena, U32 size, U32 align)
|
||||
Assert(IsPow2(align));
|
||||
|
||||
MemoryBlock *block = arena->current;
|
||||
U32 start_pos = AlignUpPow2(block->pos, align);
|
||||
U32 start_pos = AlignUpPow2(block->pos, align); // might align past block->size
|
||||
U32 available = block->size - start_pos;
|
||||
|
||||
if (available < size) {
|
||||
if (start_pos > block->size || available < size) {
|
||||
U32 block_size = arena->block_size; // original user requested size
|
||||
U32 new_commit_size = arena->commit_size;
|
||||
if (size > block_size - MemoryBlock_Header_Size) {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ struct MemoryBlock {
|
||||
U8 *base;
|
||||
U32 size; // Block size, page aligned
|
||||
U32 pos; // start of next allocation
|
||||
U32 base_pos; // absolute position of base relative to the first linked arena
|
||||
U64 base_pos; // absolute position of base relative to the first linked arena
|
||||
U32 committed_pos; // end of committed region. Will be page aligned
|
||||
MemoryBlock *prev;
|
||||
};
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ void arena_dump(const Arena *arena)
|
||||
printf("base: %p\n", block->base);
|
||||
printf("size: %u\n", block->size);
|
||||
printf("pos: %u\n", block->pos);
|
||||
printf("base_pos: %u\n", block->base_pos);
|
||||
printf("base_pos: %lu\n",block->base_pos);
|
||||
printf("prev: %p\n", block->prev);
|
||||
puts("-----Arena end-");
|
||||
block = block->prev;
|
||||
|
||||
Reference in New Issue
Block a user