Skip to content

Commit b2df18a

Browse files
committed
C++: Document tests better
This addresses PR comments by @rdmarsh2.
1 parent ef601cf commit b2df18a

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

cpp/ql/test/library-tests/dataflow/fields/by_reference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ void test_setThroughNonMember() {
6666
void test_nonMemberSetA() {
6767
S s;
6868
nonMemberSetA(&s, user_input());
69-
sink(nonMemberGetA(&s)); // flow [NOT DETECTED due to lack of flow through &]
69+
sink(nonMemberGetA(&s)); // flow
7070
}

cpp/ql/test/library-tests/dataflow/fields/flow.expected

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ edges
219219
| struct_init.c:26:23:29:3 | {...} [nestedAB, a] | struct_init.c:31:8:31:12 | outer [nestedAB, a] |
220220
| struct_init.c:26:23:29:3 | {...} [nestedAB, a] | struct_init.c:36:11:36:15 | outer [nestedAB, a] |
221221
| struct_init.c:26:23:29:3 | {...} [pointerAB, a] | struct_init.c:33:8:33:12 | outer [pointerAB, a] |
222-
| struct_init.c:26:23:29:3 | {...} [pointerAB, a] | struct_init.c:37:10:37:14 | outer [pointerAB, a] |
223222
| struct_init.c:27:5:27:23 | {...} [a] | struct_init.c:26:23:29:3 | {...} [nestedAB, a] |
224223
| struct_init.c:27:7:27:16 | call to user_input | struct_init.c:27:5:27:23 | {...} [a] |
225224
| struct_init.c:28:5:28:7 | & ... [a] | struct_init.c:26:23:29:3 | {...} [pointerAB, a] |
@@ -230,8 +229,12 @@ edges
230229
| struct_init.c:36:10:36:24 | & ... [a] | struct_init.c:14:24:14:25 | ab [a] |
231230
| struct_init.c:36:11:36:15 | outer [nestedAB, a] | struct_init.c:36:17:36:24 | nestedAB [a] |
232231
| struct_init.c:36:17:36:24 | nestedAB [a] | struct_init.c:36:10:36:24 | & ... [a] |
233-
| struct_init.c:37:10:37:14 | outer [pointerAB, a] | struct_init.c:37:16:37:24 | pointerAB [a] |
234-
| struct_init.c:37:16:37:24 | pointerAB [a] | struct_init.c:14:24:14:25 | ab [a] |
232+
| struct_init.c:40:17:40:36 | {...} [a] | struct_init.c:43:5:43:7 | & ... [a] |
233+
| struct_init.c:40:20:40:29 | call to user_input | struct_init.c:40:17:40:36 | {...} [a] |
234+
| struct_init.c:41:23:44:3 | {...} [pointerAB, a] | struct_init.c:46:10:46:14 | outer [pointerAB, a] |
235+
| struct_init.c:43:5:43:7 | & ... [a] | struct_init.c:41:23:44:3 | {...} [pointerAB, a] |
236+
| struct_init.c:46:10:46:14 | outer [pointerAB, a] | struct_init.c:46:16:46:24 | pointerAB [a] |
237+
| struct_init.c:46:16:46:24 | pointerAB [a] | struct_init.c:14:24:14:25 | ab [a] |
235238
nodes
236239
| A.cpp:41:15:41:21 | new | semmle.label | new |
237240
| A.cpp:43:10:43:12 | & ... | semmle.label | & ... |
@@ -495,8 +498,12 @@ nodes
495498
| struct_init.c:36:10:36:24 | & ... [a] | semmle.label | & ... [a] |
496499
| struct_init.c:36:11:36:15 | outer [nestedAB, a] | semmle.label | outer [nestedAB, a] |
497500
| struct_init.c:36:17:36:24 | nestedAB [a] | semmle.label | nestedAB [a] |
498-
| struct_init.c:37:10:37:14 | outer [pointerAB, a] | semmle.label | outer [pointerAB, a] |
499-
| struct_init.c:37:16:37:24 | pointerAB [a] | semmle.label | pointerAB [a] |
501+
| struct_init.c:40:17:40:36 | {...} [a] | semmle.label | {...} [a] |
502+
| struct_init.c:40:20:40:29 | call to user_input | semmle.label | call to user_input |
503+
| struct_init.c:41:23:44:3 | {...} [pointerAB, a] | semmle.label | {...} [pointerAB, a] |
504+
| struct_init.c:43:5:43:7 | & ... [a] | semmle.label | & ... [a] |
505+
| struct_init.c:46:10:46:14 | outer [pointerAB, a] | semmle.label | outer [pointerAB, a] |
506+
| struct_init.c:46:16:46:24 | pointerAB [a] | semmle.label | pointerAB [a] |
500507
#select
501508
| A.cpp:43:10:43:12 | & ... | A.cpp:41:15:41:21 | new | A.cpp:43:10:43:12 | & ... | & ... flows from $@ | A.cpp:41:15:41:21 | new | new |
502509
| A.cpp:49:13:49:13 | c | A.cpp:47:12:47:18 | new | A.cpp:49:13:49:13 | c | c flows from $@ | A.cpp:47:12:47:18 | new | new |
@@ -544,6 +551,7 @@ nodes
544551
| simple.cpp:29:12:29:12 | call to b | simple.cpp:42:12:42:21 | call to user_input | simple.cpp:29:12:29:12 | call to b | call to b flows from $@ | simple.cpp:42:12:42:21 | call to user_input | call to user_input |
545552
| struct_init.c:15:12:15:12 | a | struct_init.c:20:20:20:29 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:20:20:20:29 | call to user_input | call to user_input |
546553
| struct_init.c:15:12:15:12 | a | struct_init.c:27:7:27:16 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:27:7:27:16 | call to user_input | call to user_input |
554+
| struct_init.c:15:12:15:12 | a | struct_init.c:40:20:40:29 | call to user_input | struct_init.c:15:12:15:12 | a | a flows from $@ | struct_init.c:40:20:40:29 | call to user_input | call to user_input |
547555
| struct_init.c:22:11:22:11 | a | struct_init.c:20:20:20:29 | call to user_input | struct_init.c:22:11:22:11 | a | a flows from $@ | struct_init.c:20:20:20:29 | call to user_input | call to user_input |
548556
| struct_init.c:31:23:31:23 | a | struct_init.c:27:7:27:16 | call to user_input | struct_init.c:31:23:31:23 | a | a flows from $@ | struct_init.c:27:7:27:16 | call to user_input | call to user_input |
549557
| struct_init.c:33:25:33:25 | a | struct_init.c:20:20:20:29 | call to user_input | struct_init.c:33:25:33:25 | a | a flows from $@ | struct_init.c:20:20:20:29 | call to user_input | call to user_input |

cpp/ql/test/library-tests/dataflow/fields/struct_init.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct Outer {
1212
};
1313

1414
void absink(struct AB *ab) {
15-
sink(ab->a); // flow (three paths)
15+
sink(ab->a); // flow (three sources)
1616
sink(ab->b); // no flow
1717
}
1818

@@ -34,5 +34,14 @@ int struct_init(void) {
3434
sink(outer.pointerAB->b); // no flow
3535

3636
absink(&outer.nestedAB);
37+
}
38+
39+
int struct_init2(void) {
40+
struct AB ab = { user_input(), 0 };
41+
struct Outer outer = {
42+
{ user_input(), 0 },
43+
&ab,
44+
};
45+
3746
absink(outer.pointerAB);
3847
}

0 commit comments

Comments
 (0)