2 /// A variable is dereference under a NULL test.
3 /// Even though it is know to be NULL.
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
18 @initialize:python depends on !context && patch && !org && !report@
21 print >> sys.stderr, "This semantic patch does not support the 'patch' mode."
26 this_rule_should_never_matches();
28 @ifm depends on !patch@
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@
44 (E != NULL && ...) ? <+...E->f@p1...+> : ...
46 @pr2 depends on !patch expression@
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;
67 statement S1,S2,S3,S4;
69 position p!={pr1.p1,pr2.p2};
73 if@p1 ((E == NULL && ...) || ...)
75 ... when != if (...) S1 else S2
77 iter(subE,...) S4 // no use
79 list_remove_head(E2,subE,...)
83 for(subE = E1;...;...) S4
102 @script:python depends on !context && !patch && !org && report@
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@
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;
128 statement S1,S2,S3,S4;
130 position p!={pr1.p1,pr2.p2};
134 if@p1 ((E == NULL && ...) || ...)
136 ... when != if (...) S1 else S2
138 iter(subE,...) S4 // no use
140 list_remove_head(E2,subE,...)
144 for(subE = E1;...;...) S4
162 @script:python depends on !context && !patch && !org && report@
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@
177 msg="ERROR: %s is NULL but dereferenced." % (x)
178 msg_safe=msg.replace("[","@(").replace("]",")")
179 cocci.print_main(msg_safe,p)
183 @depends on context && !patch && !org && !report exists@
184 expression subE <= ifm.E;
188 statement S1,S2,S3,S4;
190 position p!={pr1.p1,pr2.p2};
194 if@p1 ((E == NULL && ...) || ...)
196 ... when != if (...) S1 else S2
198 iter(subE,...) S4 // no use
200 list_remove_head(E2,subE,...)
204 for(subE = E1;...;...) S4
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@
232 if@p1 ((E == NULL && ...) || ...) S1 else S2
234 @pr11 depends on !patch expression@
240 (E != NULL && ...) ? <+...E->f@p1...+> : ...
242 @pr12 depends on !patch expression@
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;
261 statement S1,S2,S3,S4;
263 position p!={pr11.p1,pr12.p2};
267 if@p1 ((E == NULL && ...) || ...)
269 ... when != if (...) S1 else S2
271 iter(subE,...) S4 // no use
273 list_remove_head(E2,subE,...)
277 for(subE = E1;...;...) S4