]> git.proxmox.com Git - mirror_frr.git/blame - tools/coccinelle/xcalloc-simple.cocci
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / tools / coccinelle / xcalloc-simple.cocci
CommitLineData
25af5f0d
QY
1///
2/// Use zeroing allocator rather than allocator followed by memset with 0
3///
4/// This considers some simple cases that are common and easy to validate
5/// Note in particular that there are no ...s in the rule, so all of the
6/// matched code has to be contiguous
7///
8// Confidence: High
9// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2.
10// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2.
11// Copyright: (C) 2017 Himanshu Jha GPLv2.
12// Copyright: (C) 2019 Quentin Young. GPLv2.
13// URL: http://coccinelle.lip6.fr/rules/kzalloc.html
14// Options: --no-includes --include-headers
15//
16// Keywords: XMALLOC, XCALLOC
17// Version min: < 2.6.12 kmalloc
18// Version min: 2.6.14 kzalloc
19//
20
21virtual context
22virtual patch
23
24//----------------------------------------------------------
25// For context mode
26//----------------------------------------------------------
27
28@depends on context@
29type T, T2;
30expression x;
31expression E1;
32expression t;
33@@
34
35* x = (T)XMALLOC(t, E1);
36* memset((T2)x,0,E1);
37
38//----------------------------------------------------------
39// For patch mode
40//----------------------------------------------------------
41
42@depends on patch@
43type T, T2;
44expression x;
45expression E1;
46expression t;
47@@
48
49- x = (T)XMALLOC(t, E1);
50+ x = (T)XCALLOC(t, E1);
51- memset((T2)x,0,E1);
52