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 // Comments: 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 @@ << 24 let negtable = Hashtbl.create 101 22 let negtable = Hashtbl.create 101 25 23 26 @depends on patch@ 24 @depends on patch@ 27 expression *E; 25 expression *E; 28 identifier f; 26 identifier f; 29 @@ 27 @@ 30 28 31 ( 29 ( 32 (E = f(...)) == 30 (E = f(...)) == 33 - 0 31 - 0 34 + NULL 32 + NULL 35 | 33 | 36 (E = f(...)) != 34 (E = f(...)) != 37 - 0 35 - 0 38 + NULL 36 + NULL 39 | 37 | 40 - 0 38 - 0 41 + NULL 39 + NULL 42 == (E = f(...)) 40 == (E = f(...)) 43 | 41 | 44 - 0 42 - 0 45 + NULL 43 + NULL 46 != (E = f(...)) 44 != (E = f(...)) 47 ) 45 ) 48 46 49 47 50 @t1 depends on !patch@ 48 @t1 depends on !patch@ 51 expression *E; 49 expression *E; 52 identifier f; 50 identifier f; 53 position p; 51 position p; 54 @@ 52 @@ 55 53 56 ( 54 ( 57 (E = f(...)) == 55 (E = f(...)) == 58 * 0@p 56 * 0@p 59 | 57 | 60 (E = f(...)) != 58 (E = f(...)) != 61 * 0@p 59 * 0@p 62 | 60 | 63 * 0@p 61 * 0@p 64 == (E = f(...)) 62 == (E = f(...)) 65 | 63 | 66 * 0@p 64 * 0@p 67 != (E = f(...)) 65 != (E = f(...)) 68 ) 66 ) 69 67 70 @script:python depends on org@ 68 @script:python depends on org@ 71 p << t1.p; 69 p << t1.p; 72 @@ 70 @@ 73 71 74 coccilib.org.print_todo(p[0], "WARNING compari 72 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0") 75 73 76 @script:python depends on report@ 74 @script:python depends on report@ 77 p << t1.p; 75 p << t1.p; 78 @@ 76 @@ 79 77 80 coccilib.report.print_report(p[0], "WARNING co 78 coccilib.report.print_report(p[0], "WARNING comparing pointer to 0") 81 79 82 // Tests of returned values 80 // Tests of returned values 83 81 84 @s@ 82 @s@ 85 identifier f; 83 identifier f; 86 expression E,E1; 84 expression E,E1; 87 @@ 85 @@ 88 86 89 E = f(...) 87 E = f(...) 90 ... when != E = E1 88 ... when != E = E1 91 !E 89 !E 92 90 93 @script:ocaml depends on s@ 91 @script:ocaml depends on s@ 94 f << s.f; 92 f << s.f; 95 @@ 93 @@ 96 94 97 try let _ = Hashtbl.find negtable f in () 95 try let _ = Hashtbl.find negtable f in () 98 with Not_found -> Hashtbl.add negtable f () 96 with Not_found -> Hashtbl.add negtable f () 99 97 100 @ r disable is_zero,isnt_zero exists @ 98 @ r disable is_zero,isnt_zero exists @ 101 expression *E; 99 expression *E; 102 identifier f; 100 identifier f; 103 @@ 101 @@ 104 102 105 E = f(...) 103 E = f(...) 106 ... 104 ... 107 (E == 0 105 (E == 0 108 |E != 0 106 |E != 0 109 |0 == E 107 |0 == E 110 |0 != E 108 |0 != E 111 ) 109 ) 112 110 113 @script:ocaml@ 111 @script:ocaml@ 114 f << r.f; 112 f << r.f; 115 @@ 113 @@ 116 114 117 try let _ = Hashtbl.find negtable f in () 115 try let _ = Hashtbl.find negtable f in () 118 with Not_found -> include_match false 116 with Not_found -> include_match false 119 117 120 // This rule may lead to inconsistent path pro 118 // This rule may lead to inconsistent path problems, if E is defined in two 121 // places 119 // places 122 @ depends on patch disable is_zero,isnt_zero @ 120 @ depends on patch disable is_zero,isnt_zero @ 123 expression *E; 121 expression *E; 124 expression E1; 122 expression E1; 125 identifier r.f; 123 identifier r.f; 126 @@ 124 @@ 127 125 128 E = f(...) 126 E = f(...) 129 <... 127 <... 130 ( 128 ( 131 - E == 0 129 - E == 0 132 + !E 130 + !E 133 | 131 | 134 - E != 0 132 - E != 0 135 + E 133 + E 136 | 134 | 137 - 0 == E 135 - 0 == E 138 + !E 136 + !E 139 | 137 | 140 - 0 != E 138 - 0 != E 141 + E 139 + E 142 ) 140 ) 143 ...> 141 ...> 144 ?E = E1 142 ?E = E1 145 143 146 @t2 depends on !patch disable is_zero,isnt_zer 144 @t2 depends on !patch disable is_zero,isnt_zero @ 147 expression *E; 145 expression *E; 148 expression E1; 146 expression E1; 149 identifier r.f; 147 identifier r.f; 150 position p1; 148 position p1; 151 position p2; 149 position p2; 152 @@ 150 @@ 153 151 154 E = f(...) 152 E = f(...) 155 <... 153 <... 156 ( 154 ( 157 * E == 0@p1 155 * E == 0@p1 158 | 156 | 159 * E != 0@p2 157 * E != 0@p2 160 | 158 | 161 * 0@p1 == E 159 * 0@p1 == E 162 | 160 | 163 * 0@p1 != E 161 * 0@p1 != E 164 ) 162 ) 165 ...> 163 ...> 166 ?E = E1 164 ?E = E1 167 165 168 @script:python depends on org@ 166 @script:python depends on org@ 169 p << t2.p1; 167 p << t2.p1; 170 @@ 168 @@ 171 169 172 coccilib.org.print_todo(p[0], "WARNING compari 170 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0, suggest !E") 173 171 174 @script:python depends on org@ 172 @script:python depends on org@ 175 p << t2.p2; 173 p << t2.p2; 176 @@ 174 @@ 177 175 178 coccilib.org.print_todo(p[0], "WARNING compari 176 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0") 179 177 180 @script:python depends on report@ 178 @script:python depends on report@ 181 p << t2.p1; 179 p << t2.p1; 182 @@ 180 @@ 183 181 184 coccilib.report.print_report(p[0], "WARNING co 182 coccilib.report.print_report(p[0], "WARNING comparing pointer to 0, suggest !E") 185 183 186 @script:python depends on report@ 184 @script:python depends on report@ 187 p << t2.p2; 185 p << t2.p2; 188 @@ 186 @@ 189 187 190 coccilib.report.print_report(p[0], "WARNING co 188 coccilib.report.print_report(p[0], "WARNING comparing pointer to 0") 191 189 192 @ depends on patch disable is_zero,isnt_zero @ 190 @ depends on patch disable is_zero,isnt_zero @ 193 expression *E; 191 expression *E; 194 @@ 192 @@ 195 193 196 ( 194 ( 197 E == 195 E == 198 - 0 196 - 0 199 + NULL 197 + NULL 200 | 198 | 201 E != 199 E != 202 - 0 200 - 0 203 + NULL 201 + NULL 204 | 202 | 205 - 0 203 - 0 206 + NULL 204 + NULL 207 == E 205 == E 208 | 206 | 209 - 0 207 - 0 210 + NULL 208 + NULL 211 != E 209 != E 212 ) 210 ) 213 211 214 @ t3 depends on !patch disable is_zero,isnt_ze 212 @ t3 depends on !patch disable is_zero,isnt_zero @ 215 expression *E; 213 expression *E; 216 position p; 214 position p; 217 @@ 215 @@ 218 216 219 ( 217 ( 220 * E == 0@p 218 * E == 0@p 221 | 219 | 222 * E != 0@p 220 * E != 0@p 223 | 221 | 224 * 0@p == E 222 * 0@p == E 225 | 223 | 226 * 0@p != E 224 * 0@p != E 227 ) 225 ) 228 226 229 @script:python depends on org@ 227 @script:python depends on org@ 230 p << t3.p; 228 p << t3.p; 231 @@ 229 @@ 232 230 233 coccilib.org.print_todo(p[0], "WARNING compari 231 coccilib.org.print_todo(p[0], "WARNING comparing pointer to 0") 234 232 235 @script:python depends on report@ 233 @script:python depends on report@ 236 p << t3.p; 234 p << t3.p; 237 @@ 235 @@ 238 236 239 coccilib.report.print_report(p[0], "WARNING co 237 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.