Fix Arena realloc bug

This commit is contained in:
2025-08-28 13:27:53 -04:00
parent a32356e298
commit a73a463936

View File

@@ -77,11 +77,7 @@ void *ArenaAllocator::realloc_raw(void *ptr, uint32_t old_size,
assert(current_block_ &&
"realloc called with non-null ptr but no current block exists");
// Assert that offset is large enough (should always be true for
// valid callers)
assert(current_block_->offset >= old_size &&
"offset must be >= old_size for valid last allocation");
if (current_block_->offset >= old_size) {
// Check if this was the last allocation by comparing with expected location
char *expected_last_alloc_start =
current_block_->data() + current_block_->offset - old_size;
@@ -105,6 +101,7 @@ void *ArenaAllocator::realloc_raw(void *ptr, uint32_t old_size,
return new_size == 0 ? nullptr : ptr;
}
}
}
// Can't extend in place
if (new_size == 0) {