Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49ef677

Browse files
committed
C++: Additional test case for function pointers.
1 parent 144c19d commit 49ef677

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

cpp/ql/test/library-tests/dataflow/models-as-data/FlowSummaryNode.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@
7272
| tests.cpp:422:6:422:25 | [summary] to write: Argument[0].Parameter[0] in madCallArg0WithValue | ArgumentNode | madCallArg0WithValue | madCallArg0WithValue |
7373
| tests.cpp:422:6:422:25 | [summary] to write: Argument[0].Parameter[this] in madCallArg0WithValue | ArgumentNode | madCallArg0WithValue | madCallArg0WithValue |
7474
| tests.cpp:422:6:422:25 | [summary] to write: Argument[1] in madCallArg0WithValue | PostUpdateNode | madCallArg0WithValue | madCallArg0WithValue |
75+
| tests.cpp:423:5:423:36 | [summary param] 1 in madCallReturnValueIgnoreFunction | ParameterNode | madCallReturnValueIgnoreFunction | madCallReturnValueIgnoreFunction |
76+
| tests.cpp:423:5:423:36 | [summary] to write: ReturnValue in madCallReturnValueIgnoreFunction | ReturnNode | madCallReturnValueIgnoreFunction | madCallReturnValueIgnoreFunction |

cpp/ql/test/library-tests/dataflow/models-as-data/SummaryCall.expected

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ summarizedCallables
2828
| tests.cpp:420:5:420:29 | madCallArg0ReturnToReturn |
2929
| tests.cpp:421:9:421:38 | madCallArg0ReturnToReturnFirst |
3030
| tests.cpp:422:6:422:25 | madCallArg0WithValue |
31+
| tests.cpp:423:5:423:36 | madCallReturnValueIgnoreFunction |
3132
sourceCallables
3233
| tests.cpp:3:5:3:10 | source |
3334
| tests.cpp:4:6:4:14 | sourcePtr |
@@ -206,7 +207,11 @@ sourceCallables
206207
| tests.cpp:421:46:421:52 | fun_ptr |
207208
| tests.cpp:422:34:422:40 | fun_ptr |
208209
| tests.cpp:422:53:422:57 | value |
209-
| tests.cpp:424:5:424:14 | getTainted |
210-
| tests.cpp:425:6:425:13 | useValue |
211-
| tests.cpp:425:19:425:19 | x |
212-
| tests.cpp:427:6:427:27 | test_function_pointers |
210+
| tests.cpp:423:45:423:51 | fun_ptr |
211+
| tests.cpp:423:64:423:68 | value |
212+
| tests.cpp:425:5:425:14 | getTainted |
213+
| tests.cpp:426:6:426:13 | useValue |
214+
| tests.cpp:426:19:426:19 | x |
215+
| tests.cpp:427:6:427:17 | dontUseValue |
216+
| tests.cpp:427:23:427:23 | x |
217+
| tests.cpp:429:6:429:27 | test_function_pointers |

cpp/ql/test/library-tests/dataflow/models-as-data/testModels.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private class TestSummaries extends SummaryModelCsv {
9797
";;false;madCallArg0ReturnToReturn;;;Argument[0].ReturnValue;ReturnValue;value",
9898
";;false;madCallArg0ReturnToReturnFirst;;;Argument[0].ReturnValue;ReturnValue.first;value",
9999
";;false;madCallArg0WithValue;;;Argument[1];Argument[0].Parameter[0];value",
100+
";;false;madCallReturnValueIgnoreFunction;;;Argument[1];ReturnValue;value",
100101
]
101102
}
102103
}

cpp/ql/test/library-tests/dataflow/models-as-data/tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,11 @@ struct intPair {
420420
int madCallArg0ReturnToReturn(int (*fun_ptr)()); // $ interpretElement
421421
intPair madCallArg0ReturnToReturnFirst(int (*fun_ptr)()); // $ interpretElement
422422
void madCallArg0WithValue(void (*fun_ptr)(int), int value); // $ interpretElement
423+
int madCallReturnValueIgnoreFunction(void (*fun_ptr)(int), int value); // $ interpretElement
423424

424425
int getTainted() { return source(); }
425426
void useValue(int x) { sink(x); }
427+
void dontUseValue(int x) { }
426428

427429
void test_function_pointers() {
428430
sink(madCallArg0ReturnToReturn(&notASource));
@@ -433,4 +435,6 @@ void test_function_pointers() {
433435
madCallArg0WithValue(&useValue, 0);
434436
madCallArg0WithValue(&useValue, source()); // $ MISSING: ir
435437
madCallArg0WithValue(&sink, source()); // $ MISSING: ir
438+
madCallReturnValueIgnoreFunction(&sink, source());
439+
sink(madCallReturnValueIgnoreFunction(&dontUseValue, source())); // $ ir
436440
}

0 commit comments

Comments
 (0)