Skip to content

Commit e419ea0

Browse files
committed
C++: Test showing no flow through aggregate init
1 parent fdd8de7 commit e419ea0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
void sink(void *o);
2+
void *user_input(void);
3+
4+
struct AB {
5+
void *a;
6+
void *b;
7+
};
8+
9+
struct Outer {
10+
struct AB nestedAB;
11+
struct AB *pointerAB;
12+
};
13+
14+
void absink(struct AB *ab) {
15+
sink(ab->a); // flow x3 [NOT DETECTED]
16+
sink(ab->b); // no flow
17+
}
18+
19+
int struct_init(void) {
20+
struct AB ab = { user_input(), 0 };
21+
22+
sink(ab.a); // flow [NOT DETECTED]
23+
sink(ab.b); // no flow
24+
absink(&ab);
25+
26+
struct Outer outer = {
27+
{ user_input(), 0 },
28+
&ab,
29+
};
30+
31+
sink(outer.nestedAB.a); // flow [NOT DETECTED]
32+
sink(outer.nestedAB.b); // no flow
33+
sink(outer.pointerAB->a); // flow [NOT DETECTED]
34+
sink(outer.pointerAB->b); // no flow
35+
36+
absink(&outer.nestedAB);
37+
absink(outer.pointerAB);
38+
}

0 commit comments

Comments
 (0)