From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- tests/programs/quarantine.zc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/programs/quarantine.zc (limited to 'tests/programs/quarantine.zc') diff --git a/tests/programs/quarantine.zc b/tests/programs/quarantine.zc new file mode 100644 index 0000000..5e3e188 --- /dev/null +++ b/tests/programs/quarantine.zc @@ -0,0 +1,25 @@ +// free quarantines the block. a stale alias still reads it, and freeing +// through the alias does nothing because the header already says free. +// unchecked so the analyzer doesn't reject the use after free. +unchecked fn main() { + let p = new(4), q, r, i = 0, t, bad = 0; + p[0] = 111; p[1] = 222; p[2] = 333; p[3] = 444; + q = p; + r = p + 2; + free(p); + while (i < 400) { t = new(4); t[0] = 999; t[1] = 888; t[2] = 777; t[3] = 666; i++; } + if (q[0] != 111 || q[1] != 222 || r[0] != 333 || r[1] != 444) bad = 1; + free(q); + if (q[0] != 111 || q[1] != 222) bad = 2; + gc(); // q still points at the block, so the sweep must not reuse it + if (q[0] != 111 || r[0] != 333) bad = 3; + p = 0; q = 0; r = 0; t = 0; + scrub(); + gc(); + t = new(4); + t[0] = 1234; + put_n(bad); put_c(' '); + put_n(t[0]); put_c(10); + free(t); + return 0; +} -- cgit v1.2.3