1// Test the behavior of malloc called from std:: when the allocation size
2// exceeds the sanitizer's allocator max allowed one.
3
4// RUN: %clangxx -O0 %s -o %t
5// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
6
7// UBSAN has no allocator.
8// UNSUPPORTED: ubsan
9
10// REQUIRES: x86_64-target-arch
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <vector>
15
16int main(int argc, char **argv) {
17 // The maximum value of all supported sanitizers (search for
18 // kMaxAllowedMallocSize). For ASan + LSan, ASan limit is used.
19 constexpr size_t kMaxAllowedMallocSizePlusOne = (1ULL << 40) + 1;
20
21 std::vector<char> v;
22 v.resize(new_size: kMaxAllowedMallocSizePlusOne);
23
24 fprintf(stderr, format: "x: %lx\n", (long)v.data());
25
26 return 0;
27}
28
29// CHECK: #{{[0-9]+.*}}allocator_returns_null_std.cpp
30// CHECK: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null_std.cpp.*}} in main
31

source code of compiler-rt/test/sanitizer_common/TestCases/Linux/allocator_returns_null_std.cpp