1 | // RUN: %clangxx_hwasan -O0 %s -o %t |
2 | // RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s |
3 | // RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL |
4 | |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | |
8 | int main() { |
9 | void *p = reinterpret_cast<void*>(42); |
10 | int res = posix_memalign(memptr: &p, alignment: 17, size: 100); |
11 | // CHECK: ERROR: HWAddressSanitizer: invalid alignment requested in posix_memalign: 17 |
12 | // CHECK: {{#0 0x.* in .*posix_memalign}} |
13 | // CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cpp:}}[[@LINE-3]] |
14 | // CHECK: SUMMARY: HWAddressSanitizer: invalid-posix-memalign-alignment {{.*}} in main |
15 | |
16 | printf(format: "pointer after failed posix_memalign: %zd\n" , (size_t)p); |
17 | // CHECK-NULL: pointer after failed posix_memalign: 42 |
18 | |
19 | return 0; |
20 | } |
21 | |