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
23 if@p1 ((E == NULL && ...) || ...) S1 else S2
25 // The following two rules are separate, because both can match a single
26 // expression in different ways
33 (E != NULL && ...) ? <+...E->f@p1...+> : ...
42 (E != NULL) && ... && <+...E->f@p2...+>
44 (E == NULL) || ... || <+...E->f@p2...+>
46 sizeof(<+...E->f@p2...+>)
49 // For org and report modes
51 @r depends on !context && (org || report) exists@
52 expression subE <= ifm.E;
56 statement S1,S2,S3,S4;
58 position p!={pr1.p1,pr2.p2};
62 if@p1 ((E == NULL && ...) || ...)
64 ... when != if (...) S1 else S2
66 iter(subE,...) S4 // no use
68 list_remove_head(E2,subE,...)
72 for(subE = E1;...;...) S4
91 @script:python depends on !context && !org && report@
97 msg="ERROR: %s is NULL but dereferenced." % (x)
98 coccilib.report.print_report(p[0], msg)
99 cocci.include_match(False)
101 @script:python depends on !context && org && !report@
107 msg="ERROR: %s is NULL but dereferenced." % (x)
108 msg_safe=msg.replace("[","@(").replace("]",")")
109 cocci.print_main(msg_safe,p)
110 cocci.include_match(False)
112 @s depends on !context && (org || report) exists@
113 expression subE <= ifm.E;
117 statement S1,S2,S3,S4;
119 position p!={pr1.p1,pr2.p2};
123 if@p1 ((E == NULL && ...) || ...)
125 ... when != if (...) S1 else S2
127 iter(subE,...) S4 // no use
129 list_remove_head(E2,subE,...)
133 for(subE = E1;...;...) S4
151 @script:python depends on !context && !org && report@
157 msg="ERROR: %s is NULL but dereferenced." % (x)
158 coccilib.report.print_report(p[0], msg)
160 @script:python depends on !context && org && !report@
166 msg="ERROR: %s is NULL but dereferenced." % (x)
167 msg_safe=msg.replace("[","@(").replace("]",")")
168 cocci.print_main(msg_safe,p)
172 @depends on context && !org && !report exists@
173 expression subE <= ifm.E;
177 statement S1,S2,S3,S4;
179 position p!={pr1.p1,pr2.p2};
183 if@p1 ((E == NULL && ...) || ...)
185 ... when != if (...) S1 else S2
187 iter(subE,...) S4 // no use
189 list_remove_head(E2,subE,...)
193 for(subE = E1;...;...) S4
212 // The following three rules are duplicates of ifm, pr1 and pr2 respectively.
213 // It is need because the previous rule as already made a "change".
221 if@p1 ((E == NULL && ...) || ...) S1 else S2
229 (E != NULL && ...) ? <+...E->f@p1...+> : ...
238 (E != NULL) && ... && <+...E->f@p2...+>
240 (E == NULL) || ... || <+...E->f@p2...+>
242 sizeof(<+...E->f@p2...+>)
245 @depends on context && !org && !report exists@
246 expression subE <= ifm1.E;
250 statement S1,S2,S3,S4;
252 position p!={pr11.p1,pr12.p2};
256 if@p1 ((E == NULL && ...) || ...)
258 ... when != if (...) S1 else S2
260 iter(subE,...) S4 // no use
262 list_remove_head(E2,subE,...)
266 for(subE = E1;...;...) S4