GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / scripts / coccinelle / deref_null.cocci
blob9969d76d0f4b13027819522ca1cd4092afb40bd3
1 ///
2 /// A variable is dereference under a NULL test.
3 /// Even though it is know to be NULL.
4 ///
5 // Confidence: Moderate
6 // Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
7 // Copyright: (C) 2010 Julia Lawall, DIKU.  GPLv2.
8 // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.  GPLv2.
9 // URL: http://coccinelle.lip6.fr/
10 // Comments: -I ... -all_includes can give more complete results
11 // Options:
13 virtual context
14 virtual patch
15 virtual org
16 virtual report
18 @initialize:python depends on !context && patch && !org && !report@
20 import sys
21 print >> sys.stderr, "This semantic patch does not support the 'patch' mode."
23 @depends on patch@
26 this_rule_should_never_matches();
28 @ifm depends on !patch@
29 expression *E;
30 statement S1,S2;
31 position p1;
34 if@p1 ((E == NULL && ...) || ...) S1 else S2
36 // The following two rules are separate, because both can match a single
37 // expression in different ways
38 @pr1 depends on !patch expression@
39 expression *ifm.E;
40 identifier f;
41 position p1;
44  (E != NULL && ...) ? <+...E->f@p1...+> : ...
46 @pr2 depends on !patch expression@
47 expression *ifm.E;
48 identifier f;
49 position p2;
53   (E != NULL) && ... && <+...E->f@p2...+>
55   (E == NULL) || ... || <+...E->f@p2...+>
57  sizeof(<+...E->f@p2...+>)
60 // For org and report modes
62 @r depends on !context && !patch && (org || report) exists@
63 expression subE <= ifm.E;
64 expression *ifm.E;
65 expression E1,E2;
66 identifier f;
67 statement S1,S2,S3,S4;
68 iterator iter;
69 position p!={pr1.p1,pr2.p2};
70 position ifm.p1;
73 if@p1 ((E == NULL && ...) || ...)
75   ... when != if (...) S1 else S2
77  iter(subE,...) S4 // no use
79  list_remove_head(E2,subE,...)
81  subE = E1
83  for(subE = E1;...;...) S4
85  subE++
87  ++subE
89  --subE
91  subE--
93  &subE
95  E->f@p // bad use
97   ... when any
98   return ...;
100 else S3
102 @script:python depends on !context && !patch && !org && report@
103 p << r.p;
104 p1 << ifm.p1;
105 x << ifm.E;
108 msg="ERROR: %s is NULL but dereferenced." % (x)
109 coccilib.report.print_report(p[0], msg)
110 cocci.include_match(False)
112 @script:python depends on !context && !patch && org && !report@
113 p << r.p;
114 p1 << ifm.p1;
115 x << ifm.E;
118 msg="ERROR: %s is NULL but dereferenced." % (x)
119 msg_safe=msg.replace("[","@(").replace("]",")")
120 cocci.print_main(msg_safe,p)
121 cocci.include_match(False)
123 @s depends on !context && !patch && (org || report) exists@
124 expression subE <= ifm.E;
125 expression *ifm.E;
126 expression E1,E2;
127 identifier f;
128 statement S1,S2,S3,S4;
129 iterator iter;
130 position p!={pr1.p1,pr2.p2};
131 position ifm.p1;
134 if@p1 ((E == NULL && ...) || ...)
136   ... when != if (...) S1 else S2
138  iter(subE,...) S4 // no use
140  list_remove_head(E2,subE,...)
142  subE = E1
144  for(subE = E1;...;...) S4
146  subE++
148  ++subE
150  --subE
152  subE--
154  &subE
156  E->f@p // bad use
158   ... when any
160 else S3
162 @script:python depends on !context && !patch && !org && report@
163 p << s.p;
164 p1 << ifm.p1;
165 x << ifm.E;
168 msg="ERROR: %s is NULL but dereferenced." % (x)
169 coccilib.report.print_report(p[0], msg)
171 @script:python depends on !context && !patch && org && !report@
172 p << s.p;
173 p1 << ifm.p1;
174 x << ifm.E;
177 msg="ERROR: %s is NULL but dereferenced." % (x)
178 msg_safe=msg.replace("[","@(").replace("]",")")
179 cocci.print_main(msg_safe,p)
181 // For context mode
183 @depends on context && !patch && !org && !report exists@
184 expression subE <= ifm.E;
185 expression *ifm.E;
186 expression E1,E2;
187 identifier f;
188 statement S1,S2,S3,S4;
189 iterator iter;
190 position p!={pr1.p1,pr2.p2};
191 position ifm.p1;
194 if@p1 ((E == NULL && ...) || ...)
196   ... when != if (...) S1 else S2
198  iter(subE,...) S4 // no use
200  list_remove_head(E2,subE,...)
202  subE = E1
204  for(subE = E1;...;...) S4
206  subE++
208  ++subE
210  --subE
212  subE--
214  &subE
216 * E->f@p // bad use
218   ... when any
219   return ...;
221 else S3
223 // The following three rules are duplicates of ifm, pr1 and pr2 respectively.
224 // It is need because the previous rule as already made a "change".
226 @ifm1 depends on !patch@
227 expression *E;
228 statement S1,S2;
229 position p1;
232 if@p1 ((E == NULL && ...) || ...) S1 else S2
234 @pr11 depends on !patch expression@
235 expression *ifm1.E;
236 identifier f;
237 position p1;
240  (E != NULL && ...) ? <+...E->f@p1...+> : ...
242 @pr12 depends on !patch expression@
243 expression *ifm1.E;
244 identifier f;
245 position p2;
249   (E != NULL) && ... && <+...E->f@p2...+>
251   (E == NULL) || ... || <+...E->f@p2...+>
253  sizeof(<+...E->f@p2...+>)
256 @depends on context && !patch && !org && !report exists@
257 expression subE <= ifm1.E;
258 expression *ifm1.E;
259 expression E1,E2;
260 identifier f;
261 statement S1,S2,S3,S4;
262 iterator iter;
263 position p!={pr11.p1,pr12.p2};
264 position ifm1.p1;
267 if@p1 ((E == NULL && ...) || ...)
269   ... when != if (...) S1 else S2
271  iter(subE,...) S4 // no use
273  list_remove_head(E2,subE,...)
275  subE = E1
277  for(subE = E1;...;...) S4
279  subE++
281  ++subE
283  --subE
285  subE--
287  &subE
289 * E->f@p // bad use
291   ... when any
293 else S3