1 | // RUN: %clangxx -fsanitize=pointer-overflow %s -o %t |
2 | // RUN: %run %t 2 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=ERR2 |
3 | // RUN: %run %t 1 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=ERR1 |
4 | // RUN: %run %t 0 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE |
5 | // RUN: %run %t -1 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE |
6 | // RUN: %run %t -2 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE |
7 | |
8 | #include <stdio.h> |
9 | #include <stdint.h> |
10 | #include <stdlib.h> |
11 | |
12 | int main(int argc, char *argv[]) { |
13 | // SAFE-NOT: runtime error |
14 | // ERR2: runtime error: pointer index expression with base {{.*}} overflowed to |
15 | // ERR2: runtime error: pointer index expression with base {{.*}} overflowed to |
16 | // ERR1: runtime error: applying non-zero offset to non-null pointer 0x{{.*}} produced null pointer |
17 | // ERR1: runtime error: applying non-zero offset to non-null pointer 0x{{.*}} produced null pointer |
18 | |
19 | char *p = (char *)(UINTPTR_MAX); |
20 | |
21 | printf(format: "%p\n" , p + atoi(nptr: argv[1])); |
22 | |
23 | char *q = (char *)(UINTPTR_MAX); |
24 | |
25 | printf(format: "%p\n" , p - (-atoi(nptr: argv[1]))); |
26 | |
27 | return 0; |
28 | } |
29 | |