v1.2.5 - Fix alignment above alignof(max_align_t) and stale marker rewinds
This commit is contained in:
40
test.c
40
test.c
@@ -160,6 +160,45 @@ static void test_snapshot_rewind_trim_logic(void)
|
||||
arena_free(&arena);
|
||||
}
|
||||
|
||||
static void test_invalid_markers(void)
|
||||
{
|
||||
printf("Running invalid marker tests...\n");
|
||||
Arena arena = arena_create(128);
|
||||
|
||||
void *first = arena_alloc(&arena, 100); // Region 1 (Cap: 128)
|
||||
assert(is_aligned(first));
|
||||
ArenaMarker mark_r1 = arena_snapshot(&arena);
|
||||
|
||||
arena_alloc(&arena, 200); // Region 2 (Cap: 256)
|
||||
ArenaMarker mark_r2 = arena_snapshot(&arena);
|
||||
|
||||
// Free Region 2, invalidating mark_r2
|
||||
arena_rewind(&arena, mark_r1);
|
||||
arena_trim(&arena);
|
||||
assert(count_regions(&arena) == 1);
|
||||
|
||||
// Stale marker must be rejected without touching freed memory
|
||||
arena_rewind(&arena, mark_r2);
|
||||
assert(arena.tail == mark_r1.region);
|
||||
assert(arena.tail->count == mark_r1.count);
|
||||
|
||||
// Marker from another arena
|
||||
Arena other = arena_create(128);
|
||||
arena_alloc(&other, 10);
|
||||
arena_rewind(&arena, arena_snapshot(&other));
|
||||
assert(arena.tail == mark_r1.region);
|
||||
assert(arena.tail->count == mark_r1.count);
|
||||
arena_free(&other);
|
||||
|
||||
// Marker with a count beyond the region capacity
|
||||
ArenaMarker forged = mark_r1;
|
||||
forged.count = mark_r1.region->capacity + 1;
|
||||
arena_rewind(&arena, forged);
|
||||
assert(arena.tail->count == mark_r1.count);
|
||||
|
||||
arena_free(&arena);
|
||||
}
|
||||
|
||||
static void test_massive_string_formatting(void)
|
||||
{
|
||||
printf("Running massive string formatting tests...\n");
|
||||
@@ -204,6 +243,7 @@ int main(void)
|
||||
test_overflows();
|
||||
test_geometric_growth_and_stress();
|
||||
test_snapshot_rewind_trim_logic();
|
||||
test_invalid_markers();
|
||||
test_massive_string_formatting();
|
||||
test_zero_capacity_fallback();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user