blob: 59b417eed38f1b4c87544095a2d67145aa3fc521 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
extern char *something();
void test1() {
int *p;
p = (int *)22; // expected-note{{Pointer value of (int *)22 stored to 'p'}}
*p = 2; // expected-warning{{Dereference of a fixed address (loaded from variable 'p')}} \
// expected-note{{Dereference of a fixed address (loaded from variable 'p')}}
}
void test2_1(int *p) {
*p = 1; // expected-warning{{Dereference of a fixed address (loaded from variable 'p')}} \
// expected-note{{Dereference of a fixed address (loaded from variable 'p')}}
}
void test2() {
int *p = (int *)11; // expected-note{{'p' initialized to (int *)11}}
test2_1(p); // expected-note{{Passing pointer value (int *)11 via 1st parameter 'p'}} \
// expected-note{{Calling 'test2_1'}}
}
struct test3_s {
int a;
};
void test3() {
struct test3_s *x;
unsigned long long val = 1111111; // expected-note{{'val' initialized to 1111111}}
x = (struct test3_s *)val; // expected-note{{Pointer value of (struct test3_s *)1111111 stored to 'x'}}
x->a = 3; // expected-warning{{Access to field 'a' results in a dereference of a fixed address (loaded from variable 'x')}} \
// expected-note{{Access to field 'a' results in a dereference of a fixed address (loaded from variable 'x')}}
}
char *test4_1() {
char *ret;
ret = something(); // expected-note{{Value assigned to 'ret'}}
if (ret == (char *)-1) // expected-note{{Assuming the condition is true}} \
// expected-note{{Taking true branch}}
return ret; // expected-note{{Returning pointer (loaded from 'ret')}}
return 0;
}
void test4() {
char *x;
x = test4_1(); // expected-note{{Calling 'test4_1'}} \
// expected-note{{Returning from 'test4_1'}} \
// expected-note{{Pointer value of (char *)-1 stored to 'x'}}
*x = 3; // expected-warning{{Dereference of a fixed address (loaded from variable 'x')}} \
// expected-note{{Dereference of a fixed address (loaded from variable 'x')}}
}
|