.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /// Bool initializations should use true and false. Bool tests don't need |
---|
2 | 3 | /// comparisons. Based on contributions from Joe Perches, Rusty Russell |
---|
3 | 4 | /// and Bruce W Allan. |
---|
4 | 5 | /// |
---|
5 | 6 | // Confidence: High |
---|
6 | | -// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2. |
---|
7 | | -// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. |
---|
| 7 | +// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. |
---|
| 8 | +// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. |
---|
8 | 9 | // URL: http://coccinelle.lip6.fr/ |
---|
9 | 10 | // Options: --include-headers |
---|
10 | 11 | |
---|
.. | .. |
---|
13 | 14 | virtual org |
---|
14 | 15 | virtual report |
---|
15 | 16 | |
---|
| 17 | +@boolok@ |
---|
| 18 | +symbol true,false; |
---|
| 19 | +@@ |
---|
| 20 | +( |
---|
| 21 | +true |
---|
| 22 | +| |
---|
| 23 | +false |
---|
| 24 | +) |
---|
| 25 | + |
---|
16 | 26 | @depends on patch@ |
---|
17 | 27 | bool t; |
---|
18 | | -symbol true; |
---|
19 | | -symbol false; |
---|
20 | 28 | @@ |
---|
21 | 29 | |
---|
22 | 30 | ( |
---|
.. | .. |
---|
63 | 71 | + t |
---|
64 | 72 | ) |
---|
65 | 73 | |
---|
66 | | -@depends on patch@ |
---|
| 74 | +@depends on patch && boolok@ |
---|
67 | 75 | bool b; |
---|
68 | 76 | @@ |
---|
69 | 77 | ( |
---|
.. | .. |
---|
116 | 124 | * t@p != 0 |
---|
117 | 125 | ) |
---|
118 | 126 | |
---|
119 | | -@r3 depends on !patch@ |
---|
| 127 | +@r3 depends on !patch && boolok@ |
---|
120 | 128 | bool b; |
---|
121 | | -position p1,p2; |
---|
122 | | -constant c; |
---|
| 129 | +position p1; |
---|
123 | 130 | @@ |
---|
124 | 131 | ( |
---|
125 | 132 | *b@p1 = 0 |
---|
126 | 133 | | |
---|
127 | 134 | *b@p1 = 1 |
---|
| 135 | +) |
---|
| 136 | + |
---|
| 137 | +@r4 depends on !patch@ |
---|
| 138 | +bool b; |
---|
| 139 | +position p2; |
---|
| 140 | +identifier i; |
---|
| 141 | +constant c != {0,1}; |
---|
| 142 | +@@ |
---|
| 143 | +( |
---|
| 144 | + b = i |
---|
128 | 145 | | |
---|
129 | 146 | *b@p2 = c |
---|
130 | 147 | ) |
---|
.. | .. |
---|
139 | 156 | p << r2.p; |
---|
140 | 157 | @@ |
---|
141 | 158 | |
---|
142 | | -cocci.print_main("WARNING: Comparison of bool to 0/1",p) |
---|
| 159 | +cocci.print_main("WARNING: Comparison of 0/1 to bool variable",p) |
---|
143 | 160 | |
---|
144 | 161 | @script:python depends on org@ |
---|
145 | 162 | p1 << r3.p1; |
---|
146 | 163 | @@ |
---|
147 | 164 | |
---|
148 | | -cocci.print_main("WARNING: Assignment of bool to 0/1",p1) |
---|
| 165 | +cocci.print_main("WARNING: Assignment of 0/1 to bool variable",p1) |
---|
149 | 166 | |
---|
150 | 167 | @script:python depends on org@ |
---|
151 | | -p2 << r3.p2; |
---|
| 168 | +p2 << r4.p2; |
---|
152 | 169 | @@ |
---|
153 | 170 | |
---|
154 | | -cocci.print_main("ERROR: Assignment of bool to non-0/1 constant",p2) |
---|
| 171 | +cocci.print_main("ERROR: Assignment of non-0/1 constant to bool variable",p2) |
---|
155 | 172 | |
---|
156 | 173 | @script:python depends on report@ |
---|
157 | 174 | p << r1.p; |
---|
.. | .. |
---|
163 | 180 | p << r2.p; |
---|
164 | 181 | @@ |
---|
165 | 182 | |
---|
166 | | -coccilib.report.print_report(p[0],"WARNING: Comparison of bool to 0/1") |
---|
| 183 | +coccilib.report.print_report(p[0],"WARNING: Comparison of 0/1 to bool variable") |
---|
167 | 184 | |
---|
168 | 185 | @script:python depends on report@ |
---|
169 | 186 | p1 << r3.p1; |
---|
170 | 187 | @@ |
---|
171 | 188 | |
---|
172 | | -coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1") |
---|
| 189 | +coccilib.report.print_report(p1[0],"WARNING: Assignment of 0/1 to bool variable") |
---|
173 | 190 | |
---|
174 | 191 | @script:python depends on report@ |
---|
175 | | -p2 << r3.p2; |
---|
| 192 | +p2 << r4.p2; |
---|
176 | 193 | @@ |
---|
177 | 194 | |
---|
178 | | -coccilib.report.print_report(p2[0],"ERROR: Assignment of bool to non-0/1 constant") |
---|
| 195 | +coccilib.report.print_report(p2[0],"ERROR: Assignment of non-0/1 constant to bool variable") |
---|