Commit | Line | Data |
---|---|---|
7f004419 C |
1 | // Use the macro ARRAY_SIZE when possible |
2 | // | |
3 | // Confidence: High | |
4 | // Copyright: (C) Gilles Muller, Julia Lawall, EMN, INRIA, DIKU. GPLv2. | |
5 | // URL: http://coccinelle.lip6.fr/rules/array.html | |
6 | // Options: -I ... -all_includes can give more complete results | |
7 | virtual org | |
8 | virtual patch | |
9 | ||
10 | @i@ | |
11 | @@ | |
12 | ||
13 | #include <linux/kernel.h> | |
14 | ||
15 | ///////////////////////////////////// | |
16 | ///////////////////////////////////// | |
17 | @depends on i && patch && !org@ | |
18 | type T; | |
19 | T[] E; | |
20 | @@ | |
21 | ||
22 | - (sizeof(E)/sizeof(*E)) | |
23 | + ARRAY_SIZE(E) | |
24 | ||
25 | @depends on i && patch && !org@ | |
26 | type T; | |
27 | T[] E; | |
28 | @@ | |
29 | ||
30 | - (sizeof(E)/sizeof(E[...])) | |
31 | + ARRAY_SIZE(E) | |
32 | ||
33 | @depends on i && patch && !org@ | |
34 | type T; | |
35 | T[] E; | |
36 | @@ | |
37 | ||
38 | - (sizeof(E)/sizeof(T)) | |
39 | + ARRAY_SIZE(E) | |
40 | ||
41 | @n_patch depends on patch && !org@ | |
42 | identifier AS,E; | |
43 | @@ | |
44 | ||
45 | - #define AS(E) ARRAY_SIZE(E) | |
46 | ||
47 | @ depends on patch && !org@ | |
48 | expression E; | |
49 | identifier n_patch.AS; | |
50 | @@ | |
51 | ||
52 | - AS(E) | |
53 | + ARRAY_SIZE(E) | |
54 | ||
55 | ||
56 | ///////////////////////////////////// | |
57 | ///////////////////////////////////// | |
58 | @arr_ptr depends on i && !patch && org@ | |
59 | type T; | |
60 | T[] E; | |
61 | position p; | |
34e49164 | 62 | @@ |
7f004419 C |
63 | |
64 | (sizeof(E@p)/sizeof(*E)) | |
65 | ||
66 | @arr_tab depends on i && !patch && org@ | |
34e49164 | 67 | type T; |
7f004419 C |
68 | T[] E; |
69 | position p; | |
70 | @@ | |
71 | ||
72 | (sizeof(E@p)/sizeof(E[...])) | |
73 | ||
74 | @arr_typ depends on i && !patch && org@ | |
75 | type T; | |
76 | T[] E; | |
77 | position p; | |
78 | @@ | |
79 | ||
80 | (sizeof(E@p)/sizeof(T)) | |
81 | ||
82 | @n_org depends on !patch && org@ | |
83 | identifier AS,E; | |
34e49164 C |
84 | @@ |
85 | ||
7f004419 C |
86 | #define AS(E) ARRAY_SIZE(E) |
87 | ||
88 | @arr_def depends on !patch && org@ | |
89 | expression E; | |
90 | identifier n_org.AS; | |
91 | position p; | |
92 | @@ | |
93 | ||
94 | AS@p(E) | |
95 | ||
96 | @script:python@ | |
97 | p << arr_ptr.p; | |
98 | e << arr_ptr.E; | |
99 | @@ | |
100 | cocci.print_main(e,p) | |
101 | ||
102 | @script:python@ | |
103 | p << arr_tab.p; | |
104 | e << arr_tab.E; | |
105 | @@ | |
106 | cocci.print_main(e,p) | |
107 | ||
108 | @script:python@ | |
109 | p << arr_typ.p; | |
110 | e << arr_typ.E; | |
111 | @@ | |
112 | cocci.print_main(e,p) | |
113 | ||
114 | @script:python@ | |
115 | p << arr_def.p; | |
116 | e << arr_def.E; | |
117 | @@ | |
118 | cocci.print_main(e,p) |