Skip to content

Commit 9bc995f

Browse files
author
Daniel Kroening
authored
Merge pull request #2924 from peterschrammel/memcpy-struct-ptr
Test for memcpy with struct pointers
2 parents 15b9ec7 + 734dafb commit 9bc995f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <string.h>
2+
#include <assert.h>
3+
4+
struct without_ptr
5+
{
6+
int x;
7+
int y;
8+
};
9+
struct with_int_ptr
10+
{
11+
int *i;
12+
int j;
13+
};
14+
struct with_struct_ptr
15+
{
16+
struct without_ptr *s;
17+
int t;
18+
};
19+
20+
int main(int argc, char **argv)
21+
{
22+
struct without_ptr w;
23+
w.x = 42;
24+
w.y = 43;
25+
26+
struct without_ptr v;
27+
memcpy(&v, &w, sizeof(struct without_ptr));
28+
assert(v.x == 42);
29+
assert(v.y == 43);
30+
31+
struct with_int_ptr k;
32+
k.i = (int *)44;
33+
k.j = 45;
34+
35+
struct with_int_ptr m;
36+
memcpy(&m, &k, sizeof(struct with_int_ptr));
37+
assert(m.i == (int *)44);
38+
assert(m.j == 45);
39+
40+
struct with_struct_ptr p;
41+
p.s = &w;
42+
p.t = 46;
43+
44+
struct with_struct_ptr q;
45+
memcpy(&q, &p, sizeof(struct with_struct_ptr));
46+
assert(q.s->x == 42);
47+
assert(q.s->y == 43);
48+
assert(q.t == 46);
49+
50+
return 0;
51+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KNOWNBUG
2+
main.c
3+
--bounds-check --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
^\[main\.assertion\.5\] assertion q\.s->x == 42: SUCCESS$
8+
^\[main\.assertion\.6\] assertion q\.s->y == 43: SUCCESS$
9+
--
10+
^warning: ignoring
11+
--
12+
Issue: 2925

0 commit comments

Comments
 (0)