Release coccinelle-0.1.11rc1
[bpt/coccinelle.git] / scripts / coccicheck / cocci / null_ref.cocci
1 // Find cases where a pointer is dereferenced and then compared to NULL
2 //
3 // Confidence: High
4 // Copyright: (C) Gilles Muller, Julia Lawall, EMN, DIKU. GPLv2.
5 // URL: http://www.emn.fr/x-info/coccinelle/rules/null_ref.html
6 // Options:
7
8 virtual org,diff
9
10 @match exists@
11 expression x, E,E1;
12 identifier fld;
13 position p1,p2;
14 @@
15
16 (
17 x = E;
18 ... when != \(x = E1\|&x\)
19 x@p2 == NULL
20 ... when any
21 |
22 x = E
23 ... when != \(x = E1\|&x\)
24 x@p2 == NULL
25 ... when any
26 |
27 x != NULL && (<+...x->fld...+>)
28 |
29 x == NULL || (<+...x->fld...+>)
30 |
31 x != NULL ? (<+...x->fld...+>) : E
32 |
33 &x->fld
34 |
35 x@p1->fld
36 ... when != \(x = E\|&x\)
37 x@p2 == NULL
38 ... when any
39 )
40
41 @other_match exists@
42 expression match.x, E1, E2;
43 position match.p1,match.p2;
44 @@
45
46 (
47 x = E1
48 |
49 &x
50 )
51 ... when != \(x = E2\|&x\)
52 when != x@p1
53 x@p2
54
55 @other_match1 exists@
56 expression match.x, E2;
57 position match.p1,match.p2;
58 @@
59
60 ... when != \(x = E2\|&x\)
61 when != x@p1
62 x@p2
63
64 @ script:python depends on !other_match && !other_match1 && org@
65 p1 << match.p1;
66 p2 << match.p2;
67 @@
68
69 cocci.print_main(p1)
70 cocci.print_secs("NULL test",p2)
71
72 @depends on !other_match && !other_match1 && diff@
73 position match.p1, match.p2;
74 expression x;
75 @@
76
77 *x@p1
78 ...
79 *x@p2