xref: /llvm-project/compiler-rt/test/lsan/TestCases/realloc_too_big.c (revision 23d1b6577a50d308938b79b1dafc198ea5094766)
1 // RUN: %clang_lsan %s -o %t
2 // RUN: %env_lsan_opts=allocator_may_return_null=1:max_allocation_size_mb=16:use_stacks=0 not %run %t 2>&1 | FileCheck %s
3 
4 /// Fails when only leak sanitizer is enabled
5 // UNSUPPORTED: arm-linux, armhf-linux
6 
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 // CHECK: {{.*}}Sanitizer failed to allocate 0x1000001 bytes
12 
13 // CHECK: {{.*}}Sanitizer: detected memory leaks
14 // CHECK: {{.*}}Sanitizer: 9 byte(s) leaked in 1 allocation(s).
15 
main()16 int main() {
17   char *p = malloc(9);
18   fprintf(stderr, "nine: %p\n", p);
19   assert(realloc(p, 0x1000001) == NULL); // 16MiB+1
20   p = 0;
21 }
22