-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtest.c
More file actions
53 lines (42 loc) · 854 Bytes
/
test.c
File metadata and controls
53 lines (42 loc) · 854 Bytes
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
struct s1 {
int m1[10];
};
struct s2 {
int m1;
struct s1 m2;
};
union u {
struct s1 m1;
struct s2 m2;
};
typedef struct {
char buf[8];
} Union_t;
typedef union {
unsigned char uc[24];
struct {
Union_t prefix;
Union_t suffix;
} fnv;
struct {
unsigned char padding[16];
Union_t suffix;
} diff;
} UnionSecret_t;
void overlapping_access() {
union u u1;
u1.m2.m2 = u1.m1; // NON_COMPLIANT, different struct. u1.m2 and u1.m1
}
void cross_copy() {
UnionSecret_t hash1;
hash1.diff.suffix =
hash1.fnv.suffix; // COMPLIANT (copy across structs), but safe.
}
void internal_shift() {
UnionSecret_t hash1;
hash1.fnv.prefix = hash1.fnv.suffix; // COMPLIANT, same struct.
}
void separate_access() {
UnionSecret_t hash1, hash2;
hash2.diff.suffix = hash1.fnv.suffix; // COMPLIANT, different union.
}