Skip to content

Commit 4b4c0cd

Browse files
committed
C++: add testcases for UninitializedLocal.ql
1 parent 9218afe commit 4b4c0cd

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-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
@@ -14,3 +14,7 @@
1414
| test.cpp:378:9:378:11 | val | The variable $@ may not be initialized at this access. | test.cpp:359:6:359:8 | val | val |
1515
| test.cpp:417:10:417:10 | j | The variable $@ may not be initialized at this access. | test.cpp:414:9:414:9 | j | j |
1616
| test.cpp:436:9:436:9 | j | The variable $@ may not be initialized at this access. | test.cpp:431:9:431:9 | j | j |
17+
| test.cpp:454:2:454:2 | x | The variable $@ may not be initialized at this access. | test.cpp:452:6:452:6 | x | x |
18+
| test.cpp:460:7:460:7 | x | The variable $@ may not be initialized at this access. | test.cpp:458:6:458:6 | x | x |
19+
| test.cpp:467:2:467:2 | x | The variable $@ may not be initialized at this access. | test.cpp:464:6:464:6 | x | x |
20+
| test.cpp:474:7:474:7 | x | The variable $@ may not be initialized at this access. | test.cpp:471:6:471:6 | x | x |

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,41 @@ int test38() {
435435

436436
return j; // BAD
437437
}
438+
439+
void test39() {
440+
int x;
441+
442+
x; // GOOD, in void context
443+
}
444+
445+
void test40() {
446+
int x;
447+
448+
(void)x; // GOOD, explicitly cast to void
449+
}
450+
451+
void test41() {
452+
int x;
453+
454+
x++; // BAD
455+
}
456+
457+
void test42() {
458+
int x;
459+
460+
void(x++); // BAD
461+
}
462+
463+
void test43() {
464+
int x;
465+
int y = 1;
466+
467+
x + y; // BAD
468+
}
469+
470+
void test44() {
471+
int x;
472+
int y = 1;
473+
474+
void(x + y); // BAD
475+
}

0 commit comments

Comments
 (0)