1 // SPDX-License-Identifier: GPL-2.0-only
3 /// A variable is dereferenced under a NULL test.
4 /// Even though it is known to be NULL.
6 // Confidence: Moderate
7 // Copyright: (C) 2010 Nicolas Palix, DIKU.
8 // Copyright: (C) 2010 Julia Lawall, DIKU.
9 // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
10 // URL: http://coccinelle.lip6.fr/
11 // Comments: -I ... -all_includes can give more complete results
18 // The following two rules are separate, because both can match a single
19 // expression in different ways
26 (E != NULL && ...) ? <+...E->f@p1...+> : ...
35 (E != NULL) && ... && <+...E->f@p2...+>
37 (E == NULL) || ... || <+...E->f@p2...+>
39 sizeof(<+...E->f@p2...+>)
48 if@p1 ((E == NULL && ...) || ...) S1 else S2
50 // For org and report modes
52 @r depends on !context && (org || report) exists@
53 expression subE <= ifm.E;
57 statement S1,S2,S3,S4;
59 position p!={pr1.p1,pr2.p2};
63 if@p1 ((E == NULL && ...) || ...)
65 ... when != if (...) S1 else S2
67 iter(subE,...) S4 // no use
69 list_remove_head(E2,subE,...)
73 for(subE = E1;...;...) S4
92 @script:python depends on !context && !org && report@
98 msg="ERROR: %s is NULL but dereferenced." % (x)
99 coccilib.report.print_report(p[0], msg)
100 cocci.include_match(False)
102 @script:python depends on !context && org && !report@
108 msg="ERROR: %s is NULL but dereferenced." % (x)
109 msg_safe=msg.replace("[","@(").replace("]",")")
110 cocci.print_main(msg_safe,p)
111 cocci.include_match(False)
113 @s depends on !context && (org || report) exists@
114 expression subE <= ifm.E;
118 statement S1,S2,S3,S4;
120 position p!={pr1.p1,pr2.p2};
124 if@p1 ((E == NULL && ...) || ...)
126 ... when != if (...) S1 else S2
128 iter(subE,...) S4 // no use
130 list_remove_head(E2,subE,...)
134 for(subE = E1;...;...) S4
152 @script:python depends on !context && !org && report@
158 msg="ERROR: %s is NULL but dereferenced." % (x)
159 coccilib.report.print_report(p[0], msg)
161 @script:python depends on !context && org && !report@
167 msg="ERROR: %s is NULL but dereferenced." % (x)
168 msg_safe=msg.replace("[","@(").replace("]",")")
169 cocci.print_main(msg_safe,p)
173 @depends on context && !org && !report exists@
174 expression subE <= ifm.E;
178 statement S1,S2,S3,S4;
180 position p!={pr1.p1,pr2.p2};
184 if@p1 ((E == NULL && ...) || ...)
186 ... when != if (...) S1 else S2
188 iter(subE,...) S4 // no use
190 list_remove_head(E2,subE,...)
194 for(subE = E1;...;...) S4
213 // The following three rules are duplicates of ifm, pr1 and pr2 respectively.
214 // It is need because the previous rule as already made a "change".
216 @pr11 depends on context && !org && !report expression@
222 (E != NULL && ...) ? <+...E->f@p1...+> : ...
224 @pr12 depends on context && !org && !report expression@
231 (E != NULL) && ... && <+...E->f@p2...+>
233 (E == NULL) || ... || <+...E->f@p2...+>
235 sizeof(<+...E->f@p2...+>)
238 @ifm1 depends on context && !org && !report@
244 if@p1 ((E == NULL && ...) || ...) S1 else S2
246 @depends on context && !org && !report exists@
247 expression subE <= ifm1.E;
251 statement S1,S2,S3,S4;
253 position p!={pr11.p1,pr12.p2};
257 if@p1 ((E == NULL && ...) || ...)
259 ... when != if (...) S1 else S2
261 iter(subE,...) S4 // no use
263 list_remove_head(E2,subE,...)
267 for(subE = E1;...;...) S4