You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnp+offset; // expected-warning{{Addition of a null pointer (from variable 'p') and a probably nonzero integer value (from variable 'offset') may result in undefined behavior}}
10
+
}
11
+
12
+
int*test_add2(intoffset) {
13
+
int*p=get_pointer();
14
+
if (p) {}
15
+
if (offset) {}
16
+
returnp+offset; // expected-warning{{Addition of a null pointer (from variable 'p') and a nonzero integer value (from variable 'offset') results in undefined behavior}}
17
+
}
18
+
19
+
int*test_add3(intoffset) {
20
+
int*p=get_pointer();
21
+
if (p) {}
22
+
if (offset!=0) return0;
23
+
returnp+offset;
24
+
}
25
+
26
+
int*test_add4(intoffset) {
27
+
int*p=get_pointer();
28
+
if (p) {}
29
+
if (offset==0) return0;
30
+
returnp+offset; // expected-warning{{Addition of a null pointer (from variable 'p') and a nonzero integer value (from variable 'offset') results in undefined behavior}}
31
+
}
32
+
33
+
int*test_add5(intoffset) {
34
+
int*p=get_pointer();
35
+
if (p) {}
36
+
returnoffset+p; // expected-warning{{Addition of a probably nonzero integer value (from variable 'offset') and a null pointer (from variable 'p') may result in undefined behavior}}
37
+
}
38
+
39
+
int*test_sub1(intoffset) {
40
+
int*p=get_pointer();
41
+
if (p) {}
42
+
returnp-offset; // expected-warning{{Subtraction of a null pointer (from variable 'p') and a probably nonzero integer value (from variable 'offset') may result in undefined behavior}}
43
+
}
44
+
45
+
inttest_sub_p1() {
46
+
int*p=get_pointer();
47
+
if (p) {}
48
+
returnp-p;
49
+
}
50
+
51
+
inttest_sub_p2() {
52
+
int*p1=get_pointer();
53
+
int*p2=get_pointer();
54
+
if (p1) {}
55
+
if (p2) {}
56
+
returnp1-p2;
57
+
// expected-warning@-1{{Subtraction of a non-null pointer (from variable 'p1') and a null pointer (from variable 'p2') results in undefined behavior}}
58
+
// expected-warning@-2{{Subtraction of a null pointer (from variable 'p1') and a non-null pointer (from variable 'p2') results in undefined behavior}}
59
+
}
60
+
61
+
inttest_sub_p3() {
62
+
int*p1=get_pointer();
63
+
int*p2=get_pointer();
64
+
if (p1) {}
65
+
returnp1-p2; // expected-warning{{Subtraction of a null pointer (from variable 'p1') and a probably non-null pointer (from variable 'p2') may result in undefined behavior}}
66
+
}
67
+
68
+
structS {
69
+
char*p;
70
+
intoffset;
71
+
};
72
+
73
+
char*test_struct(structSs) {
74
+
if (s.p) {}
75
+
returns.p+s.offset; // expected-warning{{Addition of a null pointer (via field 'p') and a probably nonzero integer value (via field 'offset') may result in undefined behavior}}
0 commit comments