Skip to content

Commit 60abea1

Browse files
committed
C++: Test for cpp/uninitialized-local
1 parent 752502b commit 60abea1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/UninitializedLocal.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
edges
22
nodes
3+
| errors.cpp:4:7:4:7 | definition of x | semmle.label | definition of x |
4+
| errors.cpp:13:7:13:7 | definition of x | semmle.label | definition of x |
35
| test.cpp:11:6:11:8 | definition of foo | semmle.label | definition of foo |
46
| test.cpp:111:6:111:8 | definition of foo | semmle.label | definition of foo |
57
| test.cpp:226:7:226:7 | definition of x | semmle.label | definition of x |
@@ -14,6 +16,8 @@ nodes
1416
| test.cpp:472:6:472:6 | definition of x | semmle.label | definition of x |
1517
| test.cpp:479:6:479:6 | definition of x | semmle.label | definition of x |
1618
#select
19+
| errors.cpp:6:10:6:10 | x | errors.cpp:4:7:4:7 | definition of x | errors.cpp:4:7:4:7 | definition of x | The variable $@ may not be initialized at this access. | errors.cpp:4:7:4:7 | x | x |
20+
| errors.cpp:14:18:14:18 | x | errors.cpp:13:7:13:7 | definition of x | errors.cpp:13:7:13:7 | definition of x | The variable $@ may not be initialized at this access. | errors.cpp:13:7:13:7 | x | x |
1721
| test.cpp:12:6:12:8 | foo | test.cpp:11:6:11:8 | definition of foo | test.cpp:11:6:11:8 | definition of foo | The variable $@ may not be initialized at this access. | test.cpp:11:6:11:8 | foo | foo |
1822
| test.cpp:113:6:113:8 | foo | test.cpp:111:6:111:8 | definition of foo | test.cpp:111:6:111:8 | definition of foo | The variable $@ may not be initialized at this access. | test.cpp:111:6:111:8 | foo | foo |
1923
| test.cpp:227:3:227:3 | x | test.cpp:226:7:226:7 | definition of x | test.cpp:226:7:226:7 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:226:7:226:7 | x | x |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// semmle-extractor-options: --expect_errors
2+
3+
int f1() {
4+
int x;
5+
initialize(&x); // error expression - initialize() is not defined
6+
return x; // GOOD - assume x is initialized
7+
}
8+
9+
void * operator new(unsigned long, bool);
10+
void operator delete(void*, bool);
11+
12+
int f2() {
13+
int x;
14+
new(true) int (x); // BAD, ignore implicit error expression
15+
}

0 commit comments

Comments
 (0)