]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/coccinelle/unused.cocci
git-push.txt: fix grammar
[thirdparty/git.git] / contrib / coccinelle / unused.cocci
CommitLineData
4f40f6cb
ÆAB
1// This rule finds sequences of "unused" declerations and uses of a
2// variable, where "unused" is defined to include only calling the
3// equivalent of alloc, init & free functions on the variable.
4@@
5type T;
6identifier I;
06f5f894
ÆAB
7// STRBUF_INIT, but also e.g. STRING_LIST_INIT_DUP (so no anchoring)
8constant INIT_MACRO =~ "_INIT";
4f40f6cb 9identifier MALLOC1 =~ "^x?[mc]alloc$";
06f5f894
ÆAB
10identifier INIT_ASSIGN1 =~ "^get_worktrees$";
11identifier INIT_CALL1 =~ "^[a-z_]*_init$";
12identifier REL1 =~ "^[a-z_]*_(release|reset|clear|free)$";
13identifier REL2 =~ "^(release|clear|free)_[a-z_]*$";
4f40f6cb
ÆAB
14@@
15
16(
17- T I;
18|
19- T I = { 0 };
20|
21- T I = INIT_MACRO;
22|
23- T I = MALLOC1(...);
06f5f894
ÆAB
24|
25- T I = INIT_ASSIGN1(...);
4f40f6cb
ÆAB
26)
27
28<... when != \( I \| &I \)
29(
30- \( INIT_CALL1 \)( \( I \| &I \), ...);
31|
06f5f894
ÆAB
32- I = \( INIT_ASSIGN1 \)(...);
33|
4f40f6cb
ÆAB
34- I = MALLOC1(...);
35)
36...>
37
06f5f894
ÆAB
38(
39- \( REL1 \| REL2 \)( \( I \| &I \), ...);
40|
41- \( REL1 \| REL2 \)( \( &I \| I \) );
42)
4f40f6cb 43 ... when != \( I \| &I \)