brintos

brintos / llvm-project-archived public Read only

0
0
Text · 731 B · b930b65 Raw
22 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t2// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s3// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL4 5// REQUIRES: stable-runtime6 7#include <stdio.h>8#include <stdlib.h>9 10int main() {11  void *p = calloc(-1, 1000);12  // CHECK: {{ERROR: AddressSanitizer: calloc parameters overflow: count \* size \(.* \* 1000\) cannot be represented in type size_t}}13  // CHECK: {{#0 0x.* in .*calloc}}14  // CHECK: {{#[1-3] 0x.* in main .*calloc-overflow.cpp:}}[[@LINE-3]]15  // CHECK: SUMMARY: AddressSanitizer: calloc-overflow16 17  printf("calloc returned: %zu\n", (size_t)p);18  // CHECK-NULL: calloc returned: 019 20  return 0;21}22