Skip to content

Commit 999a55b

Browse files
committed
Add objectcopiedtoanoverlappingobject for C and update expected results
1 parent f042945 commit 999a55b

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
No expected results have yet been specified
1+
| test.c:8:3:8:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.c:8:17:8:21 | & ... | from | test.c:8:10:8:14 | & ... | to |
2+
| test.c:10:3:10:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.c:10:17:10:21 | & ... | from | test.c:10:10:10:14 | & ... | to |
3+
| test.c:11:3:11:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.c:11:17:11:17 | o | from | test.c:11:10:11:14 | ... + ... | to |
4+
| test.c:13:3:13:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.c:13:17:13:21 | ... + ... | from | test.c:13:10:13:14 | ... + ... | to |
5+
| test.c:57:3:57:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.c:57:21:57:26 | & ... | from | test.c:57:10:57:18 | & ... | to |
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <string.h>
2+
3+
int o[10];
4+
void g(void) {
5+
6+
o[2] = o[0]; // COMPLIANT
7+
8+
memcpy(&o[1], &o[0], 2); // NON_COMPLIANT
9+
memcpy(&o[2], &o[0], 2); // COMPLIANT
10+
memcpy(&o[2], &o[1], 2); // NON_COMPLIANT
11+
memcpy(o + 1, o, 2); // NON_COMPLIANT
12+
memcpy(o + 2, o, 2); // COMPLIANT
13+
memcpy(o + 2, o + 1, 2); // NON_COMPLIANT
14+
15+
// Exception 1
16+
int *p = &o[0];
17+
int *q = &o[0];
18+
19+
*p = *q; // COMPLIANT
20+
memcpy(&o[0], &o[0], 2); // COMPLIANT
21+
memcpy(o, o, 2); // COMPLIANT
22+
23+
// Exception 2
24+
memmove(&o[1], &o[0], 2u * sizeof(o[0])); // COMPLIANT
25+
}
26+
27+
struct s1 {
28+
int m1[10];
29+
};
30+
struct s2 {
31+
int m1;
32+
struct s1 m2;
33+
};
34+
union u {
35+
struct s1 m1;
36+
struct s2 m2;
37+
} u1;
38+
39+
typedef struct {
40+
char buf[8];
41+
} Union_t;
42+
union {
43+
unsigned char uc[24];
44+
struct {
45+
Union_t prefix;
46+
Union_t suffix;
47+
} fnv;
48+
struct {
49+
unsigned char padding[16];
50+
Union_t suffix;
51+
} diff;
52+
} u2;
53+
54+
void test_unions() {
55+
u1.m2.m2 = u1.m1; // NON_COMPLIANT
56+
57+
memcpy(&u1.m2.m2, &u1.m1, sizeof(u1.m1)); // NON_COMPLIANT
58+
memcpy(&u2.diff.suffix, &u2.fnv.suffix, sizeof(u2.fnv.suffix)); // COMPLIANT
59+
}
60+
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
No expected results have yet been specified
1+
| test.cpp:8:3:8:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.cpp:8:17:8:21 | & ... | from | test.cpp:8:10:8:14 | & ... | to |
2+
| test.cpp:10:3:10:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.cpp:10:17:10:21 | & ... | from | test.cpp:10:10:10:14 | & ... | to |
3+
| test.cpp:11:3:11:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.cpp:11:17:11:17 | o | from | test.cpp:11:10:11:14 | ... + ... | to |
4+
| test.cpp:13:3:13:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.cpp:13:17:13:21 | ... + ... | from | test.cpp:13:10:13:14 | ... + ... | to |
5+
| test.cpp:57:3:57:8 | call to memcpy | The object to copy $@ overlaps the object to copy $@. | test.cpp:57:21:57:26 | & ... | from | test.cpp:57:10:57:18 | & ... | to |

0 commit comments

Comments
 (0)