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