aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/bounds_heap.zc
blob: 719757e2676a2d25663311ccb4e579243da1b9c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace;
include rt;

// a pointer to the start of a live heap block is checked against exactly the
// words new asked for: rt.new(11) holds 11 words (its block holds 11 too, but
// rt.new(4) would hold 4, not the 11 its 16-word block has room for). 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(11); int* q; char* c = rt.new(3); 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;
}