Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / scripts / coccinelle / iterators / use_after_iter.cocci
blob9be48b520879e48fb53c9cdcea5a7f51b901909c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /// If list_for_each_entry, etc complete a traversal of the list, the iterator
3 /// variable ends up pointing to an address at an offset from the list head,
4 /// and not a meaningful structure.  Thus this value should not be used after
5 /// the end of the iterator.
6 //#False positives arise when there is a goto in the iterator and the
7 //#reported reference is at the label of this goto.  Some flag tests
8 //#may also cause a report to be a false positive.
9 ///
10 // Confidence: Moderate
11 // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
12 // Copyright: (C) 2012 Gilles Muller, INRIA/LIP6.
13 // URL: http://coccinelle.lip6.fr/
14 // Comments:
15 // Options: --no-includes --include-headers
17 virtual context
18 virtual org
19 virtual report
21 @r exists@
22 identifier c,member;
23 expression E,x;
24 iterator name list_for_each_entry;
25 iterator name list_for_each_entry_reverse;
26 iterator name list_for_each_entry_continue;
27 iterator name list_for_each_entry_continue_reverse;
28 iterator name list_for_each_entry_from;
29 iterator name list_for_each_entry_safe;
30 iterator name list_for_each_entry_safe_continue;
31 iterator name list_for_each_entry_safe_from;
32 iterator name list_for_each_entry_safe_reverse;
33 iterator name hlist_for_each_entry;
34 iterator name hlist_for_each_entry_continue;
35 iterator name hlist_for_each_entry_from;
36 iterator name hlist_for_each_entry_safe;
37 statement S;
38 position p1,p2;
39 type T;
43 list_for_each_entry@p1(c,...,member) { ... when != break;
44                                  when forall
45                                  when strict
48 list_for_each_entry_reverse@p1(c,...,member) { ... when != break;
49                                  when forall
50                                  when strict
53 list_for_each_entry_continue@p1(c,...,member) { ... when != break;
54                                  when forall
55                                  when strict
58 list_for_each_entry_continue_reverse@p1(c,...,member) { ... when != break;
59                                  when forall
60                                  when strict
63 list_for_each_entry_from@p1(c,...,member) { ... when != break;
64                                  when forall
65                                  when strict
68 list_for_each_entry_safe@p1(c,...,member) { ... when != break;
69                                  when forall
70                                  when strict
73 list_for_each_entry_safe_continue@p1(c,...,member) { ... when != break;
74                                  when forall
75                                  when strict
78 list_for_each_entry_safe_from@p1(c,...,member) { ... when != break;
79                                  when forall
80                                  when strict
83 list_for_each_entry_safe_reverse@p1(c,...,member) { ... when != break;
84                                  when forall
85                                  when strict
88 ...
90 list_for_each_entry(c,...) S
92 list_for_each_entry_reverse(c,...) S
94 list_for_each_entry_continue(c,...) S
96 list_for_each_entry_continue_reverse(c,...) S
98 list_for_each_entry_from(c,...) S
100 list_for_each_entry_safe(c,...) S
102 list_for_each_entry_safe(x,c,...) S
104 list_for_each_entry_safe_continue(c,...) S
106 list_for_each_entry_safe_continue(x,c,...) S
108 list_for_each_entry_safe_from(c,...) S
110 list_for_each_entry_safe_from(x,c,...) S
112 list_for_each_entry_safe_reverse(c,...) S
114 list_for_each_entry_safe_reverse(x,c,...) S
116 hlist_for_each_entry(c,...) S
118 hlist_for_each_entry_continue(c,...) S
120 hlist_for_each_entry_from(c,...) S
122 hlist_for_each_entry_safe(c,...) S
124 list_remove_head(x,c,...)
126 sizeof(<+...c...+>)
128  &c->member
130 T c;
132 c = E
134 *c@p2
137 @script:python depends on org@
138 p1 << r.p1;
139 p2 << r.p2;
142 cocci.print_main("invalid iterator index reference",p2)
143 cocci.print_secs("iterator",p1)
145 @script:python depends on report@
146 p1 << r.p1;
147 p2 << r.p2;
150 msg = "ERROR: invalid reference to the index variable of the iterator on line %s" % (p1[0].line)
151 coccilib.report.print_report(p2[0], msg)