Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/// Bool initializations should use true and false. Bool tests don't need
2/// comparisons. Based on contributions from Joe Perches, Rusty Russell
3/// and Bruce W Allan.
4///
5// Confidence: High
6// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
7// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/
9// Options: --include-headers
10
11virtual patch
12virtual context
13virtual org
14virtual report
15
16@boolok@
17symbol true,false;
18@@
19(
20true
21|
22false
23)
24
25@depends on patch@
26bool t;
27@@
28
29(
30- t == true
31+ t
32|
33- true == t
34+ t
35|
36- t != true
37+ !t
38|
39- true != t
40+ !t
41|
42- t == false
43+ !t
44|
45- false == t
46+ !t
47|
48- t != false
49+ t
50|
51- false != t
52+ t
53)
54
55@depends on patch disable is_zero, isnt_zero@
56bool t;
57@@
58
59(
60- t == 1
61+ t
62|
63- t != 1
64+ !t
65|
66- t == 0
67+ !t
68|
69- t != 0
70+ t
71)
72
73@depends on patch && boolok@
74bool b;
75@@
76(
77 b =
78- 0
79+ false
80|
81 b =
82- 1
83+ true
84)
85
86// ---------------------------------------------------------------------
87
88@r1 depends on !patch@
89bool t;
90position p;
91@@
92
93(
94* t@p == true
95|
96* true == t@p
97|
98* t@p != true
99|
100* true != t@p
101|
102* t@p == false
103|
104* false == t@p
105|
106* t@p != false
107|
108* false != t@p
109)
110
111@r2 depends on !patch disable is_zero, isnt_zero@
112bool t;
113position p;
114@@
115
116(
117* t@p == 1
118|
119* t@p != 1
120|
121* t@p == 0
122|
123* t@p != 0
124)
125
126@r3 depends on !patch && boolok@
127bool b;
128position p1;
129@@
130(
131*b@p1 = 0
132|
133*b@p1 = 1
134)
135
136@r4 depends on !patch@
137bool b;
138position p2;
139identifier i;
140constant c != {0,1};
141@@
142(
143 b = i
144|
145*b@p2 = c
146)
147
148@script:python depends on org@
149p << r1.p;
150@@
151
152cocci.print_main("WARNING: Comparison to bool",p)
153
154@script:python depends on org@
155p << r2.p;
156@@
157
158cocci.print_main("WARNING: Comparison of 0/1 to bool variable",p)
159
160@script:python depends on org@
161p1 << r3.p1;
162@@
163
164cocci.print_main("WARNING: Assignment of 0/1 to bool variable",p1)
165
166@script:python depends on org@
167p2 << r4.p2;
168@@
169
170cocci.print_main("ERROR: Assignment of non-0/1 constant to bool variable",p2)
171
172@script:python depends on report@
173p << r1.p;
174@@
175
176coccilib.report.print_report(p[0],"WARNING: Comparison to bool")
177
178@script:python depends on report@
179p << r2.p;
180@@
181
182coccilib.report.print_report(p[0],"WARNING: Comparison of 0/1 to bool variable")
183
184@script:python depends on report@
185p1 << r3.p1;
186@@
187
188coccilib.report.print_report(p1[0],"WARNING: Assignment of 0/1 to bool variable")
189
190@script:python depends on report@
191p2 << r4.p2;
192@@
193
194coccilib.report.print_report(p2[0],"ERROR: Assignment of non-0/1 constant to bool variable")