diff options
author | Nicolas Palix <npalix@diku.dk> | 2010-08-24 11:39:02 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2010-08-31 05:37:53 -0400 |
commit | afc48a82fafe55dbeeaf7c0d83d29cf279cb1c70 (patch) | |
tree | 5d6c5ff7aa828aeb7d3470ee969c6888526d5ee1 /scripts/coccinelle | |
parent | 4045159253a49a56d117148d67bc86a72762a0d3 (diff) |
Coccinelle: Add iterators/itnull.cocci
Many iterators have the property that the first argument is always bound
to a real list element, never NULL. False positives arise for some
iterators that do not have this property, or in cases when the loop
cursor is reassigned. The latter should only happen when the matched
code is on the way to a loop exit (break, goto, or return).
Signed-off-by: Nicolas Palix <npalix@diku.dk>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r-- | scripts/coccinelle/iterators/itnull.cocci | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/coccinelle/iterators/itnull.cocci b/scripts/coccinelle/iterators/itnull.cocci new file mode 100644 index 000000000000..baa4297a4ed1 --- /dev/null +++ b/scripts/coccinelle/iterators/itnull.cocci | |||
@@ -0,0 +1,58 @@ | |||
1 | /// Many iterators have the property that the first argument is always bound | ||
2 | /// to a real list element, never NULL. False positives arise for some | ||
3 | /// iterators that do not have this property, or in cases when the loop | ||
4 | /// cursor is reassigned. The latter should only happen when the matched | ||
5 | /// code is on the way to a loop exit (break, goto, or return). | ||
6 | /// | ||
7 | // Confidence: Moderate | ||
8 | // Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2. | ||
9 | // Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2. | ||
10 | // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. | ||
11 | // URL: http://coccinelle.lip6.fr/ | ||
12 | // Comments: | ||
13 | // Options: -no_includes -include_headers | ||
14 | |||
15 | virtual patch | ||
16 | |||
17 | @@ | ||
18 | iterator I; | ||
19 | expression x,E,E1,E2; | ||
20 | statement S,S1,S2; | ||
21 | @@ | ||
22 | |||
23 | I(x,...) { <... | ||
24 | ( | ||
25 | - if (x == NULL && ...) S | ||
26 | | | ||
27 | - if (x != NULL || ...) | ||
28 | S | ||
29 | | | ||
30 | - (x == NULL) || | ||
31 | E | ||
32 | | | ||
33 | - (x != NULL) && | ||
34 | E | ||
35 | | | ||
36 | - (x == NULL && ...) ? E1 : | ||
37 | E2 | ||
38 | | | ||
39 | - (x != NULL || ...) ? | ||
40 | E1 | ||
41 | - : E2 | ||
42 | | | ||
43 | - if (x == NULL && ...) S1 else | ||
44 | S2 | ||
45 | | | ||
46 | - if (x != NULL || ...) | ||
47 | S1 | ||
48 | - else S2 | ||
49 | | | ||
50 | + BAD( | ||
51 | x == NULL | ||
52 | + ) | ||
53 | | | ||
54 | + BAD( | ||
55 | x != NULL | ||
56 | + ) | ||
57 | ) | ||
58 | ...> } \ No newline at end of file | ||