1 // SPDX-License-Identifier: GPL-2.0-only << 2 /// Compare pointer-typed values to NULL rathe 1 /// Compare pointer-typed values to NULL rather than 0 3 /// 2 /// 4 //# This makes an effort to choose between !x 3 //# This makes an effort to choose between !x and x == NULL. !x is used 5 //# if it has previously been used with the fu 4 //# if it has previously been used with the function used to initialize x. 6 //# This relies on type information. More typ 5 //# This relies on type information. More type information can be obtained 7 //# using the option -all_includes and the opt 6 //# using the option -all_includes and the option -I to specify an 8 //# include path. 7 //# include path. 9 // 8 // 10 // Confidence: High 9 // Confidence: High 11 // Copyright: (C) 2012 Julia Lawall, INRIA/LIP !! 10 // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2. 12 // Copyright: (C) 2012 Gilles Muller, INRIA/Li !! 11 // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 13 // URL: https://coccinelle.gitlabpages.inria.f !! 12 // URL: http://coccinelle.lip6.fr/ 14 // Requires: 1.0.0 13 // Requires: 1.0.0 15 // Options: 14 // Options: 16 15 17 virtual patch 16 virtual patch 18 virtual context 17 virtual context 19 virtual org 18 virtual org 20 virtual report 19 virtual report 21 20 22 @initialize:ocaml@ 21 @initialize:ocaml@ 23 @@ 22 @@ 24 let negtable = Hashtbl.create 101 23 let negtable = Hashtbl.create 101 25 24 26 @depends on patch@ 25 @depends on patch@ 27 expression *E; 26 expression *E; 28 identifier f; 27 identifier f; 29 @@ 28 @@ 30 29 31 ( 30 ( 32 (E = f(...)) == 31 (E = f(...)) == 33 - 0 32 - 0 34 + NULL 33 + NULL 35 | 34 | 36 (E = f(...)) != 35 (E = f(...)) != 37 - 0 36 - 0 38 + NULL 37 + NULL 39 | 38 | 40 - 0 39 - 0 41 + NULL 40 + NULL 42 == (E = f(...)) 41 == (E = f(...)) 43 | 42 | 44 - 0 43 - 0 45 + NULL 44 + NULL 46 != (E = f(...)) 45 != (E = f(...)) 47 ) 46 ) 48 47 49 48 50 @t1 depends on !patch@ 49 @t1 depends on !patch@ 51 expression *E; 50 expression *E; 52 identifier f; 51 identifier f; 53 position p; 52 position p; 54 @@ 53 @@ 55 54 56 ( 55 ( 57 (E = f(...)) == 56 (E = f(...)) == 58 * 0@p 57 * 0@p 59 | 58 | 60 (E = f(...)) != 59 (E = f(...)) != 61 * 0@p 60 * 0@p 62 | 61 | 63 * 0@p 62 * 0@p 64 == (E = f(...)) 63 == (E = f(...)) 65 | 64 | 66 * 0@p 65 * 0@p 67 != (E = f(...)) 66 != (E = f(...)) 68 ) 67 ) 69 68 70 @script:python depends on org@ 69 @script:python depends on org@ 71 p << t1.p; 70 p << t1.p; 72 @@ 71 @@ 73 72 74 coccilib.org.print_todo(p[0], "WARNING compari 73 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0") 75 74 76 @script:python depends on report@ 75 @script:python depends on report@ 77 p << t1.p; 76 p << t1.p; 78 @@ 77 @@ 79 78 80 coccilib.report.print_report(p[0], "WARNING co 79 coccilib.report.print_report(p[0], "WARNING comparing pointer to 0") 81 80 82 // Tests of returned values 81 // Tests of returned values 83 82 84 @s@ 83 @s@ 85 identifier f; 84 identifier f; 86 expression E,E1; 85 expression E,E1; 87 @@ 86 @@ 88 87 89 E = f(...) 88 E = f(...) 90 ... when != E = E1 89 ... when != E = E1 91 !E 90 !E 92 91 93 @script:ocaml depends on s@ 92 @script:ocaml depends on s@ 94 f << s.f; 93 f << s.f; 95 @@ 94 @@ 96 95 97 try let _ = Hashtbl.find negtable f in () 96 try let _ = Hashtbl.find negtable f in () 98 with Not_found -> Hashtbl.add negtable f () 97 with Not_found -> Hashtbl.add negtable f () 99 98 100 @ r disable is_zero,isnt_zero exists @ 99 @ r disable is_zero,isnt_zero exists @ 101 expression *E; 100 expression *E; 102 identifier f; 101 identifier f; 103 @@ 102 @@ 104 103 105 E = f(...) 104 E = f(...) 106 ... 105 ... 107 (E == 0 106 (E == 0 108 |E != 0 107 |E != 0 109 |0 == E 108 |0 == E 110 |0 != E 109 |0 != E 111 ) 110 ) 112 111 113 @script:ocaml@ 112 @script:ocaml@ 114 f << r.f; 113 f << r.f; 115 @@ 114 @@ 116 115 117 try let _ = Hashtbl.find negtable f in () 116 try let _ = Hashtbl.find negtable f in () 118 with Not_found -> include_match false 117 with Not_found -> include_match false 119 118 120 // This rule may lead to inconsistent path pro 119 // This rule may lead to inconsistent path problems, if E is defined in two 121 // places 120 // places 122 @ depends on patch disable is_zero,isnt_zero @ 121 @ depends on patch disable is_zero,isnt_zero @ 123 expression *E; 122 expression *E; 124 expression E1; 123 expression E1; 125 identifier r.f; 124 identifier r.f; 126 @@ 125 @@ 127 126 128 E = f(...) 127 E = f(...) 129 <... 128 <... 130 ( 129 ( 131 - E == 0 130 - E == 0 132 + !E 131 + !E 133 | 132 | 134 - E != 0 133 - E != 0 135 + E 134 + E 136 | 135 | 137 - 0 == E 136 - 0 == E 138 + !E 137 + !E 139 | 138 | 140 - 0 != E 139 - 0 != E 141 + E 140 + E 142 ) 141 ) 143 ...> 142 ...> 144 ?E = E1 143 ?E = E1 145 144 146 @t2 depends on !patch disable is_zero,isnt_zer 145 @t2 depends on !patch disable is_zero,isnt_zero @ 147 expression *E; 146 expression *E; 148 expression E1; 147 expression E1; 149 identifier r.f; 148 identifier r.f; 150 position p1; 149 position p1; 151 position p2; 150 position p2; 152 @@ 151 @@ 153 152 154 E = f(...) 153 E = f(...) 155 <... 154 <... 156 ( 155 ( 157 * E == 0@p1 156 * E == 0@p1 158 | 157 | 159 * E != 0@p2 158 * E != 0@p2 160 | 159 | 161 * 0@p1 == E 160 * 0@p1 == E 162 | 161 | 163 * 0@p1 != E 162 * 0@p1 != E 164 ) 163 ) 165 ...> 164 ...> 166 ?E = E1 165 ?E = E1 167 166 168 @script:python depends on org@ 167 @script:python depends on org@ 169 p << t2.p1; 168 p << t2.p1; 170 @@ 169 @@ 171 170 172 coccilib.org.print_todo(p[0], "WARNING compari 171 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0, suggest !E") 173 172 174 @script:python depends on org@ 173 @script:python depends on org@ 175 p << t2.p2; 174 p << t2.p2; 176 @@ 175 @@ 177 176 178 coccilib.org.print_todo(p[0], "WARNING compari 177 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0") 179 178 180 @script:python depends on report@ 179 @script:python depends on report@ 181 p << t2.p1; 180 p << t2.p1; 182 @@ 181 @@ 183 182 184 coccilib.report.print_report(p[0], "WARNING co 183 coccilib.report.print_report(p[0], "WARNING comparing pointer to 0, suggest !E") 185 184 186 @script:python depends on report@ 185 @script:python depends on report@ 187 p << t2.p2; 186 p << t2.p2; 188 @@ 187 @@ 189 188 190 coccilib.report.print_report(p[0], "WARNING co 189 coccilib.report.print_report(p[0], "WARNING comparing pointer to 0") 191 190 192 @ depends on patch disable is_zero,isnt_zero @ 191 @ depends on patch disable is_zero,isnt_zero @ 193 expression *E; 192 expression *E; 194 @@ 193 @@ 195 194 196 ( 195 ( 197 E == 196 E == 198 - 0 197 - 0 199 + NULL 198 + NULL 200 | 199 | 201 E != 200 E != 202 - 0 201 - 0 203 + NULL 202 + NULL 204 | 203 | 205 - 0 204 - 0 206 + NULL 205 + NULL 207 == E 206 == E 208 | 207 | 209 - 0 208 - 0 210 + NULL 209 + NULL 211 != E 210 != E 212 ) 211 ) 213 212 214 @ t3 depends on !patch disable is_zero,isnt_ze 213 @ t3 depends on !patch disable is_zero,isnt_zero @ 215 expression *E; 214 expression *E; 216 position p; 215 position p; 217 @@ 216 @@ 218 217 219 ( 218 ( 220 * E == 0@p 219 * E == 0@p 221 | 220 | 222 * E != 0@p 221 * E != 0@p 223 | 222 | 224 * 0@p == E 223 * 0@p == E 225 | 224 | 226 * 0@p != E 225 * 0@p != E 227 ) 226 ) 228 227 229 @script:python depends on org@ 228 @script:python depends on org@ 230 p << t3.p; 229 p << t3.p; 231 @@ 230 @@ 232 231 233 coccilib.org.print_todo(p[0], "WARNING compari 232 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0") 234 233 235 @script:python depends on report@ 234 @script:python depends on report@ 236 p << t3.p; 235 p << t3.p; 237 @@ 236 @@ 238 237 239 coccilib.report.print_report(p[0], "WARNING co 238 coccilib.report.print_report(p[0], "WARNING comparing pointer to 0")
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.