Skip to content

Commit 1753a7e

Browse files
committed
C++: Add tests.
1 parent f05c862 commit 1753a7e

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ uniquePostUpdate
2323
postIsInSameCallable
2424
reverseRead
2525
argHasPostUpdate
26+
| flowOut.cpp:55:14:55:16 | * ... | ArgumentNode is missing PostUpdateNode. |
2627
| lambdas.cpp:18:7:18:7 | a | ArgumentNode is missing PostUpdateNode. |
2728
| lambdas.cpp:25:2:25:2 | b | ArgumentNode is missing PostUpdateNode. |
2829
| lambdas.cpp:32:2:32:2 | c | ArgumentNode is missing PostUpdateNode. |
@@ -51,7 +52,12 @@ postWithInFlow
5152
| example.c:28:23:28:25 | pos [inner post update] | PostUpdateNode should not be the target of local flow. |
5253
| flowOut.cpp:5:5:5:12 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
5354
| flowOut.cpp:5:6:5:12 | toTaint [inner post update] | PostUpdateNode should not be the target of local flow. |
55+
| flowOut.cpp:8:5:8:12 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
56+
| flowOut.cpp:8:6:8:12 | toTaint [inner post update] | PostUpdateNode should not be the target of local flow. |
5457
| flowOut.cpp:18:17:18:17 | x [inner post update] | PostUpdateNode should not be the target of local flow. |
58+
| flowOut.cpp:30:12:30:12 | x [inner post update] | PostUpdateNode should not be the target of local flow. |
59+
| flowOut.cpp:37:5:37:6 | p2 [inner post update] | PostUpdateNode should not be the target of local flow. |
60+
| flowOut.cpp:37:5:37:9 | access to array [post update] | PostUpdateNode should not be the target of local flow. |
5561
| globals.cpp:13:5:13:19 | flowTestGlobal1 [post update] | PostUpdateNode should not be the target of local flow. |
5662
| globals.cpp:23:5:23:19 | flowTestGlobal2 [post update] | PostUpdateNode should not be the target of local flow. |
5763
| lambdas.cpp:23:3:23:14 | v [post update] | PostUpdateNode should not be the target of local flow. |
Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,74 @@
1-
int source();
2-
void sink(int);
1+
int source(); char source(bool);
2+
void sink(int); void sink(char);
33

44
void source_ref(int *toTaint) { // $ ir-def=*toTaint ast-def=toTaint
55
*toTaint = source();
66
}
7-
8-
9-
7+
void source_ref(char *toTaint) { // $ ir-def=*toTaint ast-def=toTaint
8+
*toTaint = source();
9+
}
1010
void modify_copy(int* ptr) { // $ ast-def=ptr
1111
int deref = *ptr;
1212
int* other = &deref;
1313
source_ref(other);
1414
}
1515

16-
void test_output() {
16+
void test_output_copy() {
1717
int x = 0;
1818
modify_copy(&x);
1919
sink(x); // $ SPURIOUS: ir
20+
}
21+
22+
void modify(int* ptr) { // $ ast-def=ptr
23+
int* deref = ptr;
24+
int* other = &*deref;
25+
source_ref(other);
26+
}
27+
28+
void test_output() {
29+
int x = 0;
30+
modify(&x);
31+
sink(x); // $ SPURIOUS: ir MISSING: ast
32+
}
33+
34+
void modify_copy_of_pointer(int* p, unsigned len) { // $ ast-def=p
35+
int* p2 = new int[len];
36+
for(unsigned i = 0; i < len; ++i) {
37+
p2[i] = p[i];
38+
}
39+
40+
source_ref(p2);
41+
}
42+
43+
void test_modify_copy_of_pointer() {
44+
int x[10];
45+
modify_copy_of_pointer(x, 10);
46+
sink(x[0]); // $ SPURIOUS: ir,ast
47+
}
48+
49+
void modify_pointer(int* p, unsigned len) { // $ ast-def=p
50+
int** p2 = &p;
51+
for(unsigned i = 0; i < len; ++i) {
52+
*p2[i] = p[i];
53+
}
54+
55+
source_ref(*p2);
56+
}
57+
58+
void test_modify_of_pointer() {
59+
int x[10];
60+
modify_pointer(x, 10);
61+
sink(x[0]); // $ ast,ir
62+
}
63+
64+
char* strdup(const char* p);
65+
66+
void modify_copy_via_strdup(char* p) { // $ ast-def=p
67+
char* p2 = strdup(p);
68+
source_ref(p2);
69+
}
70+
71+
void test_modify_copy_via_strdup(char* p) { // $ ast-def=p
72+
modify_copy_via_strdup(p);
73+
sink(*p); // $ SPURIOUS: ir
2074
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/uninitialized.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
| flowOut.cpp:44:7:44:7 | x | flowOut.cpp:45:26:45:26 | x |
2+
| flowOut.cpp:44:7:44:7 | x | flowOut.cpp:46:8:46:8 | x |
3+
| flowOut.cpp:59:7:59:7 | x | flowOut.cpp:60:18:60:18 | x |
4+
| flowOut.cpp:59:7:59:7 | x | flowOut.cpp:61:8:61:8 | x |
15
| ref.cpp:53:9:53:10 | x1 | ref.cpp:55:19:55:20 | x1 |
26
| ref.cpp:53:9:53:10 | x1 | ref.cpp:56:10:56:11 | x1 |
37
| ref.cpp:53:13:53:14 | x2 | ref.cpp:58:15:58:16 | x2 |

0 commit comments

Comments
 (0)