aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/bounds_heap.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 16:09:07 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 16:09:07 +0330
commite228e7609929763d5acddb728ba543832fcffc6a (patch)
tree9b4ecc4d46bf38e8d20234d631a6d41543daa211 /tests/programs/bounds_heap.zc
parentmerge: memdebug obj_base via size classes (diff)
parentbounds checking: constant loop bound proof works, plain-op fixed-array check,... (diff)
merge bounds checking
Diffstat (limited to 'tests/programs/bounds_heap.zc')
-rw-r--r--tests/programs/bounds_heap.zc16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/programs/bounds_heap.zc b/tests/programs/bounds_heap.zc
new file mode 100644
index 0000000..d0bd318
--- /dev/null
+++ b/tests/programs/bounds_heap.zc
@@ -0,0 +1,16 @@
+namespace;
+include rt;
+
+// a pointer to the start of a live heap block is checked against the block's
+// payload, which a buddy block rounds up: rt.new(4) holds 11 words. a pointer
+// into the middle of a block, or to memory that is not a heap block, is not
+// checked. a char is a word, so a char* counts words.
+int main() {
+ int* p = rt.new(4); int* q; char* c = rt.new(2); int i = 10;
+ p[i] = 3; rt.put_n(p[i]); rt.put_c(10);
+ q = p + 1; i = 10; rt.put_n(q[i - 1] - 3); rt.put_c(10);
+ i = 2; c[i] = 'x'; rt.put_c(c[i]); rt.put_c(10);
+ i = 11;
+ rt.put_n(p[i]); rt.put_c(10);
+ return 0;
+}