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

Skip to content

Commit a806569

Browse files
committed
C++: The next commit is going to track flow out of both direct and indirect sources. This means we'll get a lot of duplication since there'll be flow from indirect source -> indirect sink and direct source -> direct sink (which both map to the same expressions). This commit changes the testing so that we only report a duplication when they're at different locations.
1 parent 5a8b900 commit a806569

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

cpp/ql/test/TestUtilities/dataflow/FlowTestCommon.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ class IRFlowTest extends InlineExpectationsTest {
2525
exists(IRDataFlow::Node source, IRDataFlow::Node sink, IRDataFlow::Configuration conf, int n |
2626
tag = "ir" and
2727
conf.hasFlow(source, sink) and
28-
n = strictcount(IRDataFlow::Node otherSource | conf.hasFlow(otherSource, sink)) and
28+
n =
29+
strictcount(int line, int column |
30+
conf.hasFlow(any(IRDataFlow::Node otherSource |
31+
otherSource.hasLocationInfo(_, line, column, _, _)
32+
), sink)
33+
) and
2934
(
3035
n = 1 and value = ""
3136
or
@@ -53,7 +58,12 @@ class AstFlowTest extends InlineExpectationsTest {
5358
|
5459
tag = "ast" and
5560
conf.hasFlow(source, sink) and
56-
n = strictcount(AstDataFlow::Node otherSource | conf.hasFlow(otherSource, sink)) and
61+
n =
62+
strictcount(int line, int column |
63+
conf.hasFlow(any(AstDataFlow::Node otherSource |
64+
otherSource.hasLocationInfo(_, line, column, _, _)
65+
), sink)
66+
) and
5767
(
5868
n = 1 and value = ""
5969
or

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class A
4040
cc.insert(nullptr);
4141
ct.insert(new C());
4242
sink(&cc); // no flow
43-
sink(&ct); // $ ast ir=41:15
43+
sink(&ct); // $ ast ir
4444
}
4545
void f1()
4646
{
@@ -53,7 +53,7 @@ class A
5353
{
5454
B *b = new B();
5555
b->set(new C1());
56-
sink(b->get()); // $ ast ir=55:12
56+
sink(b->get()); // $ ast ir
5757
sink((new B(new C()))->get()); // $ ast ir
5858
}
5959

@@ -63,7 +63,7 @@ class A
6363
B *b2;
6464
b2 = setOnB(b1, new C2());
6565
sink(b1->c); // no flow
66-
sink(b2->c); // $ ast ir=64:21
66+
sink(b2->c); // $ ast ir
6767
}
6868

6969
void f4()
@@ -72,7 +72,7 @@ class A
7272
B *b2;
7373
b2 = setOnBWrap(b1, new C2());
7474
sink(b1->c); // no flow
75-
sink(b2->c); // $ ast ir=73:25
75+
sink(b2->c); // $ ast ir
7676
}
7777

7878
B *setOnBWrap(B *b1, C *c)

cpp/ql/test/library-tests/dataflow/smart-pointers-taint/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void test_unique_ptr_int() {
88
std::unique_ptr<int> p2 = std::make_unique<int>(source());
99

1010
sink(*p1); // $ ir MISSING: ast
11-
sink(*p2); // $ ast ir=8:50
11+
sink(*p2); // $ ast ir
1212
}
1313

1414
struct A {
@@ -23,7 +23,7 @@ void test_unique_ptr_struct() {
2323

2424
sink(p1->x); // $ ir MISSING: ast
2525
sink(p1->y);
26-
sink(p2->x); // $ ir=22:46 MISSING: ast
26+
sink(p2->x); // $ ir MISSING: ast
2727
sink(p2->y);
2828
}
2929

@@ -32,7 +32,7 @@ void test_shared_ptr_int() {
3232
std::shared_ptr<int> p2 = std::make_shared<int>(source());
3333

3434
sink(*p1); // $ ast,ir
35-
sink(*p2); // $ ast ir=32:50
35+
sink(*p2); // $ ast ir
3636
}
3737

3838
void test_shared_ptr_struct() {

0 commit comments

Comments
 (0)