Linux Audio

Check our new training course

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