]>
Commit | Line | Data |
---|---|---|
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 | ||
21 | virtual context | |
22 | virtual patch | |
23 | ||
24 | //---------------------------------------------------------- | |
25 | // For context mode | |
26 | //---------------------------------------------------------- | |
27 | ||
28 | @depends on context@ | |
29 | type T, T2; | |
30 | expression x; | |
31 | expression E1; | |
32 | expression 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@ | |
43 | type T, T2; | |
44 | expression x; | |
45 | expression E1; | |
46 | expression t; | |
47 | @@ | |
48 | ||
49 | - x = (T)XMALLOC(t, E1); | |
50 | + x = (T)XCALLOC(t, E1); | |
51 | - memset((T2)x,0,E1); | |
52 |