1*673dc3d4SNico Weber // RUN: %clangxx_asan -O0 %s -o %t 2*673dc3d4SNico Weber // RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s 3*673dc3d4SNico Weber // RUN: %env_asan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL 4*673dc3d4SNico Weber 5*673dc3d4SNico Weber // REQUIRES: stable-runtime 6*673dc3d4SNico Weber 7*673dc3d4SNico Weber #include <stdio.h> 8*673dc3d4SNico Weber #include <stdlib.h> 9*673dc3d4SNico Weber main()10*673dc3d4SNico Weberint main() { 11*673dc3d4SNico Weber void *p = calloc(-1, 1000); 12*673dc3d4SNico Weber // CHECK: {{ERROR: AddressSanitizer: calloc parameters overflow: count \* size \(.* \* 1000\) cannot be represented in type size_t}} 13*673dc3d4SNico Weber // CHECK: {{#0 0x.* in .*calloc}} 14*673dc3d4SNico Weber // CHECK: {{#1 0x.* in main .*calloc-overflow.cpp:}}[[@LINE-3]] 15*673dc3d4SNico Weber // CHECK: SUMMARY: AddressSanitizer: calloc-overflow 16*673dc3d4SNico Weber 17*673dc3d4SNico Weber printf("calloc returned: %zu\n", (size_t)p); 18*673dc3d4SNico Weber // CHECK-NULL: calloc returned: 0 19*673dc3d4SNico Weber 20*673dc3d4SNico Weber return 0; 21*673dc3d4SNico Weber } 22