Skip to content

Commit 77c1ad4

Browse files
committed
CPP: Add test cases with lambdas.
1 parent 06dd5f3 commit 77c1ad4

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/AV Rule 79.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
| DeleteThis.cpp:60:3:60:24 | ... = ... | Resource ptr14 is acquired by class MyClass3 but not released anywhere in this class. |
1111
| DeleteThis.cpp:127:3:127:20 | ... = ... | Resource d is acquired by class MyClass9 but not released anywhere in this class. |
1212
| ExternalOwners.cpp:49:3:49:20 | ... = ... | Resource a is acquired by class MyScreen but not released anywhere in this class. |
13+
| Lambda.cpp:7:3:7:21 | ... = ... | Resource r1 is acquired by class testLambda but not released anywhere in this class. |
14+
| Lambda.cpp:12:3:12:21 | ... = ... | Resource r2 is acquired by class testLambda but not released anywhere in this class. |
15+
| Lambda.cpp:24:3:24:21 | ... = ... | Resource r4 is acquired by class testLambda but not released anywhere in this class. |
1316
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1417
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
1518
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
class testLambda
3+
{
4+
public:
5+
testLambda()
6+
{
7+
r1 = new char[4096]; // GOOD [FALSE POSITIVE]
8+
deleter1 = [](char *r) {
9+
delete [] r;
10+
};
11+
12+
r2 = new char[4096]; // GOOD [FALSE POSITIVE]
13+
auto deleter2 = [this]() {
14+
delete [] r2;
15+
};
16+
deleter2();
17+
18+
r3 = new char[4096]; // GOOD
19+
auto deleter3 = [&r = r3]() {
20+
delete [] r;
21+
};
22+
deleter3();
23+
24+
r4 = new char[4096]; // BAD
25+
}
26+
27+
~testLambda()
28+
{
29+
deleter1(r1);
30+
}
31+
32+
private:
33+
char *r1, *r2, *r3, *r4;
34+
35+
void (*deleter1)(char *r);
36+
};

0 commit comments

Comments
 (0)