1 // RUN: %clangxx_asan -O0 %s -o %t
2 // Default is true (free on realloc to 0 size)
3 // RUN: %run %t 2>&1 | FileCheck %s
4 // RUN: %env_asan_opts=allocator_frees_and_returns_null_on_realloc_zero=true %run %t 2>&1 | FileCheck %s
5 // RUN: %env_asan_opts=allocator_frees_and_returns_null_on_realloc_zero=false %run %t 2>&1 | FileCheck %s --check-prefix=NO-FREE
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 
main()10 int main() {
11   void *p = malloc(42);
12   p = realloc(p, 0);
13   if (p) {
14     // NO-FREE: Allocated something on realloc(p, 0)
15     fprintf(stderr, "Allocated something on realloc(p, 0)\n");
16   } else {
17     // CHECK: realloc(p, 0) returned nullptr
18     fprintf(stderr, "realloc(p, 0) returned nullptr\n");
19   }
20   free(p);
21 }
22