2019-06-04 10:11:38 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-02-10 22:05:18 +01:00
|
|
|
/// Bool initializations should use true and false. Bool tests don't need
|
|
|
|
/// comparisons. Based on contributions from Joe Perches, Rusty Russell
|
|
|
|
/// and Bruce W Allan.
|
|
|
|
///
|
|
|
|
// Confidence: High
|
2019-06-04 10:11:38 +02:00
|
|
|
// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
|
|
|
|
// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
|
2012-02-10 22:05:18 +01:00
|
|
|
// URL: http://coccinelle.lip6.fr/
|
2013-06-20 13:10:56 +02:00
|
|
|
// Options: --include-headers
|
2012-02-10 22:05:18 +01:00
|
|
|
|
|
|
|
virtual patch
|
|
|
|
virtual context
|
|
|
|
virtual org
|
|
|
|
virtual report
|
|
|
|
|
2018-12-12 12:55:56 +01:00
|
|
|
@boolok@
|
|
|
|
symbol true,false;
|
|
|
|
@@
|
|
|
|
(
|
|
|
|
true
|
|
|
|
|
|
|
|
|
false
|
|
|
|
)
|
|
|
|
|
2012-02-10 22:05:18 +01:00
|
|
|
@depends on patch@
|
|
|
|
bool t;
|
|
|
|
@@
|
|
|
|
|
|
|
|
(
|
|
|
|
- t == true
|
|
|
|
+ t
|
|
|
|
|
|
|
|
|
- true == t
|
|
|
|
+ t
|
|
|
|
|
|
|
|
|
- t != true
|
|
|
|
+ !t
|
|
|
|
|
|
|
|
|
- true != t
|
|
|
|
+ !t
|
|
|
|
|
|
|
|
|
- t == false
|
|
|
|
+ !t
|
|
|
|
|
|
|
|
|
- false == t
|
|
|
|
+ !t
|
|
|
|
|
|
|
|
|
- t != false
|
|
|
|
+ t
|
|
|
|
|
|
|
|
|
- false != t
|
|
|
|
+ t
|
|
|
|
)
|
|
|
|
|
|
|
|
@depends on patch disable is_zero, isnt_zero@
|
|
|
|
bool t;
|
|
|
|
@@
|
|
|
|
|
|
|
|
(
|
|
|
|
- t == 1
|
|
|
|
+ t
|
|
|
|
|
|
|
|
|
- t != 1
|
|
|
|
+ !t
|
|
|
|
|
|
|
|
|
- t == 0
|
|
|
|
+ !t
|
|
|
|
|
|
|
|
|
- t != 0
|
|
|
|
+ t
|
|
|
|
)
|
|
|
|
|
2018-12-12 12:55:56 +01:00
|
|
|
@depends on patch && boolok@
|
2012-02-10 22:05:18 +01:00
|
|
|
bool b;
|
|
|
|
@@
|
|
|
|
(
|
|
|
|
b =
|
|
|
|
- 0
|
|
|
|
+ false
|
|
|
|
|
|
|
|
|
b =
|
|
|
|
- 1
|
|
|
|
+ true
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
@r1 depends on !patch@
|
|
|
|
bool t;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
(
|
|
|
|
* t@p == true
|
|
|
|
|
|
|
|
|
* true == t@p
|
|
|
|
|
|
|
|
|
* t@p != true
|
|
|
|
|
|
|
|
|
* true != t@p
|
|
|
|
|
|
|
|
|
* t@p == false
|
|
|
|
|
|
|
|
|
* false == t@p
|
|
|
|
|
|
|
|
|
* t@p != false
|
|
|
|
|
|
|
|
|
* false != t@p
|
|
|
|
)
|
|
|
|
|
|
|
|
@r2 depends on !patch disable is_zero, isnt_zero@
|
|
|
|
bool t;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
(
|
|
|
|
* t@p == 1
|
|
|
|
|
|
|
|
|
* t@p != 1
|
|
|
|
|
|
|
|
|
* t@p == 0
|
|
|
|
|
|
|
|
|
* t@p != 0
|
|
|
|
)
|
|
|
|
|
2018-12-12 12:55:56 +01:00
|
|
|
@r3 depends on !patch && boolok@
|
2012-02-10 22:05:18 +01:00
|
|
|
bool b;
|
2018-12-12 12:55:56 +01:00
|
|
|
position p1;
|
2012-02-10 22:05:18 +01:00
|
|
|
@@
|
|
|
|
(
|
|
|
|
*b@p1 = 0
|
|
|
|
|
|
|
|
|
*b@p1 = 1
|
|
|
|
)
|
|
|
|
|
2018-12-12 12:55:56 +01:00
|
|
|
@r4 depends on !patch@
|
|
|
|
bool b;
|
|
|
|
position p2;
|
2018-12-29 07:14:16 +01:00
|
|
|
identifier i;
|
2018-12-12 12:55:56 +01:00
|
|
|
constant c != {0,1};
|
|
|
|
@@
|
2018-12-29 07:14:16 +01:00
|
|
|
(
|
|
|
|
b = i
|
|
|
|
|
|
2018-12-12 12:55:56 +01:00
|
|
|
*b@p2 = c
|
2018-12-29 07:14:16 +01:00
|
|
|
)
|
2018-12-12 12:55:56 +01:00
|
|
|
|
2012-02-10 22:05:18 +01:00
|
|
|
@script:python depends on org@
|
|
|
|
p << r1.p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
cocci.print_main("WARNING: Comparison to bool",p)
|
|
|
|
|
|
|
|
@script:python depends on org@
|
|
|
|
p << r2.p;
|
|
|
|
@@
|
|
|
|
|
2018-12-12 12:55:57 +01:00
|
|
|
cocci.print_main("WARNING: Comparison of 0/1 to bool variable",p)
|
2012-02-10 22:05:18 +01:00
|
|
|
|
|
|
|
@script:python depends on org@
|
|
|
|
p1 << r3.p1;
|
|
|
|
@@
|
|
|
|
|
2018-12-12 12:55:57 +01:00
|
|
|
cocci.print_main("WARNING: Assignment of 0/1 to bool variable",p1)
|
2012-02-10 22:05:18 +01:00
|
|
|
|
|
|
|
@script:python depends on org@
|
2018-12-12 12:55:56 +01:00
|
|
|
p2 << r4.p2;
|
2012-02-10 22:05:18 +01:00
|
|
|
@@
|
|
|
|
|
2018-12-12 12:55:57 +01:00
|
|
|
cocci.print_main("ERROR: Assignment of non-0/1 constant to bool variable",p2)
|
2012-02-10 22:05:18 +01:00
|
|
|
|
|
|
|
@script:python depends on report@
|
|
|
|
p << r1.p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
coccilib.report.print_report(p[0],"WARNING: Comparison to bool")
|
|
|
|
|
|
|
|
@script:python depends on report@
|
|
|
|
p << r2.p;
|
|
|
|
@@
|
|
|
|
|
2018-12-12 12:55:57 +01:00
|
|
|
coccilib.report.print_report(p[0],"WARNING: Comparison of 0/1 to bool variable")
|
2012-02-10 22:05:18 +01:00
|
|
|
|
|
|
|
@script:python depends on report@
|
|
|
|
p1 << r3.p1;
|
|
|
|
@@
|
|
|
|
|
2018-12-12 12:55:57 +01:00
|
|
|
coccilib.report.print_report(p1[0],"WARNING: Assignment of 0/1 to bool variable")
|
2012-02-10 22:05:18 +01:00
|
|
|
|
|
|
|
@script:python depends on report@
|
2018-12-12 12:55:56 +01:00
|
|
|
p2 << r4.p2;
|
2012-02-10 22:05:18 +01:00
|
|
|
@@
|
|
|
|
|
2018-12-12 12:55:57 +01:00
|
|
|
coccilib.report.print_report(p2[0],"ERROR: Assignment of non-0/1 constant to bool variable")
|