2008-04-11 06:16:52 +08:00
|
|
|
// RUN: clang -checker-simple -verify %s
|
2008-04-03 00:54:39 +08:00
|
|
|
|
2008-04-23 05:10:18 +08:00
|
|
|
#include<stdint.h>
|
|
|
|
|
2008-04-03 00:54:39 +08:00
|
|
|
void f1(int *p) {
|
|
|
|
if (p) *p = 1;
|
|
|
|
else *p = 0; // expected-warning{{ereference}}
|
|
|
|
}
|
2008-04-22 07:44:17 +08:00
|
|
|
|
|
|
|
struct foo_struct {
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
|
|
|
int f2(struct foo_struct* p) {
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
p->x = 1;
|
|
|
|
|
2008-04-22 07:45:26 +08:00
|
|
|
return p->x++; // expected-warning{{Dereference of null pointer.}}
|
2008-04-22 07:44:17 +08:00
|
|
|
}
|
2008-04-22 12:56:55 +08:00
|
|
|
|
|
|
|
int f3(char* x) {
|
|
|
|
|
|
|
|
int i = 2;
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
return x[i - 1];
|
|
|
|
|
|
|
|
return x[i+1]; // expected-warning{{Dereference of null pointer.}}
|
|
|
|
}
|
|
|
|
|
2008-04-30 07:25:09 +08:00
|
|
|
int f3_b(char* x) {
|
|
|
|
|
|
|
|
int i = 2;
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
return x[i - 1];
|
|
|
|
|
|
|
|
return x[i+1]++; // expected-warning{{Dereference of null pointer.}}
|
|
|
|
}
|
|
|
|
|
2008-04-23 05:10:18 +08:00
|
|
|
int f4(int *p) {
|
|
|
|
|
|
|
|
uintptr_t x = p;
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
int *q = (int*) x;
|
|
|
|
return *q; // expected-warning{{Dereference of null pointer.}}
|
2008-04-23 05:39:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int f5() {
|
|
|
|
|
|
|
|
char *s = "hello world";
|
|
|
|
return s[0]; // no-warning
|
|
|
|
}
|
|
|
|
|