Skip to content

Commit f042945

Browse files
committed
Add objectassignedtoanoverlappingobject for C and update expected results
1 parent e632ba9 commit f042945

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
No expected results have yet been specified
1+
| test.c:36:3:36:18 | ... = ... | An object $@ assigned to overlapping object $@. | test.c:36:9:36:10 | m2 | m2 | test.c:36:17:36:18 | m1 | m1 |
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
struct s1 {
2+
int m1[10];
3+
};
4+
struct s2 {
5+
int m1;
6+
struct s1 m2;
7+
};
8+
9+
union u {
10+
struct s1 m1;
11+
struct s2 m2;
12+
};
13+
14+
typedef struct {
15+
char buf[8];
16+
} Union_t;
17+
18+
typedef union {
19+
20+
unsigned char uc[24];
21+
22+
struct {
23+
Union_t prefix;
24+
Union_t suffix;
25+
} fnv;
26+
27+
struct {
28+
unsigned char padding[16];
29+
Union_t suffix;
30+
} diff;
31+
32+
} UnionSecret_t;
33+
34+
void overlapping_access() {
35+
union u u1;
36+
u1.m2.m2 = u1.m1; // NON_COMPLIANT, different struct. u1.m2 and u1.m1
37+
}
38+
39+
void cross_copy() {
40+
UnionSecret_t hash1;
41+
hash1.diff.suffix =
42+
hash1.fnv.suffix; // COMPLIANT (copy across structs), but safe.
43+
}
44+
45+
void internal_shift() {
46+
UnionSecret_t hash1;
47+
hash1.fnv.prefix = hash1.fnv.suffix; // COMPLIANT, same struct.
48+
}
49+
50+
void separate_access() {
51+
UnionSecret_t hash1, hash2;
52+
hash2.diff.suffix = hash1.fnv.suffix; // COMPLIANT, different union.
53+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
No expected results have yet been specified
1+
| test.cpp:36:3:36:18 | ... = ... | An object $@ assigned to overlapping object $@. | test.cpp:36:9:36:10 | m2 | m2 | test.cpp:36:17:36:18 | m1 | m1 |

0 commit comments

Comments
 (0)