diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 11:31:50 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 11:31:50 +0300 |
| commit | acd338ea33de36d223cc6d301712eed4a9501e6c (patch) | |
| tree | d93c46a97e2ed4e8a86e3402de5f847cdc144ec8 /tests/correctness_probe.c | |
| parent | f97c3a585e2efc1d0a4bc10e6ac04b96ee6428ea (diff) | |
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.
Diffstat (limited to 'tests/correctness_probe.c')
| -rw-r--r-- | tests/correctness_probe.c | 13 |
1 files changed, 10 insertions, 3 deletions
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; } |
