diff options
Diffstat (limited to 'tests/programs/quarantine.zc')
| -rw-r--r-- | tests/programs/quarantine.zc | 25 |
1 files changed, 25 insertions, 0 deletions
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; +} |
