Release coccinelle-0.1.11rc1
[bpt/coccinelle.git] / scripts / coccicheck / cocci / notnull.cocci
CommitLineData
951c7801
C
1// This detects NULL tests that can only be reached when the value is known
2// not to be NULL
3//
4// Confidence: High
5// Copyright: (C) Gilles Muller, Julia Lawall, EMN, DIKU. GPLv2.
6// URL: http://www.emn.fr/x-info/coccinelle/rules/notnull.html
7// Options:
8
9virtual org,diff
10
11@r exists@
12local idexpression x;
13expression E;
14position p1,p2;
15@@
16
17if (x@p1 == NULL || ...) { ... when forall
18 return ...; }
19... when != \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\)
20 when != &x
21(
22x@p2 == NULL
23|
24x@p2 != NULL
25)
26
27// another path to the test that is not through p1?
28
29@s exists@
30local idexpression r.x;
31position r.p1,r.p2;
32@@
33
34... when != x@p1
35(
36x@p2 == NULL
37|
38x@p2 != NULL
39)
40
41// another path to the test from p1?
42
43@t exists@
44local idexpression x;
45position r.p1,r.p2;
46@@
47
48if (x@p1 == NULL || ...) { ... x@p2 ... when any
49 return ...; }
50
51// another path to the test containing an assignment?
52
53@u exists@
54local idexpression x;
55expression E;
56position r.p1,r.p2;
57@@
58
59if (x@p1 == NULL || ...) { ... when forall
60 return ...; }
61 ...
62 \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\|&x\)
63 ... when != x@p1
64 when any
65(
66x@p2 == NULL
67|
68x@p2 != NULL
69)
70
71@script:python depends on !s && !t && !u && org @
72p1 << r.p1;
73p2 << r.p2;
74@@
75
76cocci.print_main("",p2)
77cocci.print_secs("",p1)
78
79@depends on !s && !t && !u && diff@
80position r.p1, r.p2;
81expression x;
82@@
83
84*x@p1
85...
86*x@p2