-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARRAY_SIZE.cocci
106 lines (77 loc) · 1.57 KB
/
ARRAY_SIZE.cocci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// empty.iso is used because there is an iso that converts sizeof(E) to
// sizeof E, which causes a double match in an expression, and thus a
// double modification
@ rule1 using "empty.iso" @
expression E;
@@
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
@ rule2 using "empty.iso" @
expression E;
@@
- sizeof(E)/sizeof(*E)
+ ARRAY_SIZE(E)
@ rule3 using "empty.iso" @
expression E, E1;
@@
- (sizeof(E)/sizeof(E[E1]))
+ ARRAY_SIZE(E)
@ rule4 using "empty.iso" @
expression E, E1;
@@
- sizeof(E)/sizeof(E[E1])
+ ARRAY_SIZE(E)
@ rule5 using "empty.iso" @
type T;
T[] E;
@@
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
@ rule6 using "empty.iso" @
type T;
T[] E;
@@
- sizeof(E)/sizeof(T)
+ ARRAY_SIZE(E)
// ---------------------------------------------------------------------------
// some of the above rules with more parentheses
// this can't be done with an isomorphism, as described above
@ rule1p using "empty.iso" @
expression E;
@@
- (sizeof(E)/sizeof(*(E)))
+ ARRAY_SIZE(E)
@ rule2p using "empty.iso" @
expression E;
@@
- sizeof(E)/sizeof(*(E))
+ ARRAY_SIZE(E)
@ rule3p using "empty.iso" @
expression E, E1;
@@
- (sizeof(E)/sizeof((E)[E1]))
+ ARRAY_SIZE(E)
@ rule4p using "empty.iso" @
expression E, E1;
@@
- sizeof(E)/sizeof((E)[E1])
+ ARRAY_SIZE(E)
// ---------------------------------------------------------------------------
@@ expression E; @@
- NUM_ELEMENTS(E)
+ ARRAY_SIZE(E)
@ rule53 @
identifier NUM, x;
@@
- #define NUM(x) ARRAY_SIZE(x)
@@
expression E;
identifier rule53.NUM;
@@
- NUM(E)
+ ARRAY_SIZE(E)
@@
expression E;
@@
- ((int)ARRAY_SIZE(E))
+ ARRAY_SIZE(E)