Anna Zaks | 9b0970f | 2011-11-16 19:58:17 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=experimental.security.taint,experimental.security.ArrayBoundV2 -verify %s |
| 2 | |
| 3 | int scanf(const char *restrict format, ...); |
| 4 | int getchar(void); |
| 5 | |
| 6 | #define BUFSIZE 10 |
| 7 | |
| 8 | int Buffer[BUFSIZE]; |
| 9 | void bufferFoo1(void) |
| 10 | { |
| 11 | int n; |
| 12 | scanf("%d", &n); |
| 13 | Buffer[n] = 1; // expected-warning {{Out of bound memory access }} |
| 14 | } |
Anna Zaks | 0d339d0 | 2011-11-17 23:07:28 +0000 | [diff] [blame] | 15 | |
| 16 | void bufferScanfArithmetic1(int x) { |
| 17 | int n; |
| 18 | scanf("%d", &n); |
| 19 | int m = (n - 3); |
| 20 | Buffer[m] = 1; // expected-warning {{Out of bound memory access }} |
| 21 | } |
| 22 | |
| 23 | void bufferScanfArithmetic2(int x) { |
| 24 | int n; |
| 25 | scanf("%d", &n); |
| 26 | int m = (n + 3) * x; |
| 27 | Buffer[m] = 1; // expected-warning {{Out of bound memory access }} |
| 28 | } |
Anna Zaks | 8f4caf5 | 2011-11-18 02:26:36 +0000 | [diff] [blame^] | 29 | |
| 30 | void scanfArg() { |
| 31 | int t; |
| 32 | scanf("%d", t); // expected-warning {{Pointer argument is expected}} |
| 33 | } |