| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s |
| 2 |
|
| 3 |
int test1(void) { |
| 4 |
int *p = (int *)sizeof(int); |
| 5 |
p -= 1; |
| 6 |
return *p; // expected-warning {{Dereference of null pointer}} |
| 7 |
} |
| 8 |
|
| 9 |
int test2(void) { |
| 10 |
int *p = (int *)sizeof(int); |
| 11 |
p -= 2; |
| 12 |
p += 1; |
| 13 |
return *p; // expected-warning {{Dereference of null pointer}} |
| 14 |
} |
| 15 |
|
| 16 |
int test3(void) { |
| 17 |
int *p = (int *)sizeof(int); |
| 18 |
p++; |
| 19 |
p--; |
| 20 |
p--; |
| 21 |
return *p; // expected-warning {{Dereference of null pointer}} |
| 22 |
} |
| 23 |
|
| 24 |
int test4(void) { |
| 25 |
// This is a special case where pointer arithmetic is not calculated to |
| 26 |
// preserve useful warnings on dereferences of null pointers. |
| 27 |
int *p = 0; |
| 28 |
p += 1; |
| 29 |
return *p; // expected-warning {{Dereference of null pointer}} |
| 30 |
} |