From acd338ea33de36d223cc6d301712eed4a9501e6c Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 11:31:50 +0300 Subject: Fix snapshot storage and allocation failure correctness Account for cluster records discarded by snapshot scrolling, propagate snapshot allocation failures with an empty retryable view, and allocate resized screens before mutating visible state. Add bounded-memory and allocation-failure regressions, and update the saved diagnostic and audit report. --- tests/correctness_probe.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'tests/correctness_probe.c') diff --git a/tests/correctness_probe.c b/tests/correctness_probe.c index 0b55211..a7c15df 100644 --- a/tests/correctness_probe.c +++ b/tests/correctness_probe.c @@ -26,6 +26,7 @@ void *__wrap_realloc(void *ptr, size_t size) int main(void) { + bool failed = false; struct term_options options = { .size = { 8, 3 }, .scrollback = 5 }; struct term *t = term_new(&options); struct term_snapshot *s = term_snapshot_new(); @@ -35,11 +36,14 @@ int main(void) fail_realloc = 1; bool ok = term_snapshot_update(s, t); uint32_t cps[16]; - int n = term_snapshot_cluster(s, term_snapshot_row(s, 0)[0].text, cps, 16); - printf("snapshot arena allocation failure: update=%d cluster_length=%d (expected false, or length 2)\n", ok, n); + const struct term_cell *row = term_snapshot_row(s, 0); + int n = row ? term_snapshot_cluster(s, row[0].text, cps, 16) : 0; + printf("snapshot arena allocation failure: update=%d cluster_length=%d (expected false and empty)\n", ok, n); + failed |= ok || term_snapshot_view(s)->size.x != 0 || term_snapshot_view(s)->size.y != 0; assert(term_snapshot_update(s, t)); n = term_snapshot_cluster(s, term_snapshot_row(s, 0)[0].text, cps, 16); printf("retry after allocation recovers: cluster_length=%d (expected 2)\n", n); + failed |= n != 2 || cps[0] != 'e' || cps[1] != 0x301; term_snapshot_free(s); term_free(t); @@ -55,6 +59,7 @@ int main(void) printf("after %d lines: arena_words=%u dead_words=%u history_rows=%d\n", i, s->arena_len, s->arena_dead, term_history_rows(t)); } + failed |= s->arena_len >= 8192 || term_history_rows(t) != 5; term_snapshot_free(s); term_free(t); @@ -74,7 +79,9 @@ int main(void) printf("after failed height shrink: resize=%d height=%d top=%c cursor_y=%d history=%d\n", ok, term_size(t).y, (char)term_snapshot_row(s, 0)[0].text, term_cursor(t).pos.y, term_history_rows(t)); + failed |= ok || term_size(t).y != 4 || term_snapshot_row(s, 0)[0].text != 'A' || + term_cursor(t).pos.y != 3 || term_history_rows(t) != 0; term_snapshot_free(s); term_free(t); - return 0; + return failed ? 1 : 0; } -- cgit v1.2.3