1 // Test that malloc_zone_from_ptr returns a valid zone for a 0-sized allocation.
2 // Test that malloc_size does not crash for an invalid pointer.
4 // RUN: %clang_tsan %s -o %t -framework Foundation
5 // RUN: %run %t 2>&1 | FileCheck %s
7 #include <malloc/malloc.h>
14 void describe_zone(void *p) {
15 malloc_zone_t *z = malloc_zone_from_ptr(p);
17 fprintf(stderr, "zone = %p\n", z);
19 fprintf(stderr, "zone = no zone\n");
29 fprintf(stderr, "size = 0x%zx\n", s);
32 // CHECK: zone = 0x{{[0-9a-f]+}}
36 fprintf(stderr, "size = 0x%zx\n", s);
39 // CHECK: zone = 0x{{[0-9a-f]+}}
43 fprintf(stderr, "size = 0x%zx\n", s);
46 // CHECK: zone = no zone
48 p = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
50 fprintf(stderr, "mmap failed\n");
54 fprintf(stderr, "size = 0x%zx\n", s);
57 // CHECK: zone = no zone
59 p = (void *)0x42; // invalid pointer
61 fprintf(stderr, "size = 0x%zx\n", s);
64 // CHECK: zone = no zone