CPP: Additional test cases.

This commit is contained in:
Geoffrey White
2019-05-21 16:41:32 +01:00
parent 41d5d5ab86
commit 12bbb0755f
2 changed files with 162 additions and 1 deletions

View File

@@ -8,3 +8,12 @@
| test.cpp:132:9:132:9 | j | The variable $@ may not be initialized here. | test.cpp:126:6:126:6 | j | j |
| test.cpp:219:3:219:3 | x | The variable $@ may not be initialized here. | test.cpp:218:7:218:7 | x | x |
| test.cpp:243:13:243:13 | i | The variable $@ may not be initialized here. | test.cpp:241:6:241:6 | i | i |
| test.cpp:268:9:268:11 | val | The variable $@ may not be initialized here. | test.cpp:261:6:261:8 | val | val |
| test.cpp:292:9:292:11 | val | The variable $@ may not be initialized here. | test.cpp:285:6:285:8 | val | val |
| test.cpp:304:9:304:11 | val | The variable $@ may not be initialized here. | test.cpp:297:6:297:8 | val | val |
| test.cpp:316:9:316:11 | val | The variable $@ may not be initialized here. | test.cpp:309:6:309:8 | val | val |
| test.cpp:329:9:329:11 | val | The variable $@ may not be initialized here. | test.cpp:321:6:321:8 | val | val |
| test.cpp:336:10:336:10 | a | The variable $@ may not be initialized here. | test.cpp:333:7:333:7 | a | a |
| test.cpp:342:9:342:11 | val | The variable $@ may not be initialized here. | test.cpp:334:6:334:8 | val | val |
| test.cpp:369:10:369:10 | a | The variable $@ may not be initialized here. | test.cpp:358:7:358:7 | a | a |
| test.cpp:378:9:378:11 | val | The variable $@ may not be initialized here. | test.cpp:359:6:359:8 | val | val |

View File

@@ -242,4 +242,156 @@ void test21()
v3 = v1 >> i; // BAD: i is not initialized
v3 = v2 >> 1; // BAD: v2 is not initialized [NOT DETECTED]
}
}
int test22() {
bool loop = true;
int val;
while (loop)
{
val = 1;
loop = false;
}
return val; // GOOD
}
int test23() {
bool loop = true, stop = false;
int val;
while (loop && true)
{
val = 1;
loop = false;
}
return val; // GOOD [FALSE POSITIVE]
}
int test24() {
bool stop = false;
int val;
while (!stop)
{
val = 1;
stop = true;
}
return val; // GOOD
}
int test25() {
bool loop = true, stop = false;
int val;
while (true && loop)
{
val = 1;
loop = false;
}
return val; // GOOD [FALSE POSITIVE]
}
int test26() {
bool loop = true, stop = false;
int val;
while (loop && loop)
{
val = 1;
loop = false;
}
return val; // GOOD [FALSE POSITIVE]
}
int test27() {
bool loop = true, stop = false;
int val;
while (loop || false)
{
val = 1;
loop = false;
}
return val; // GOOD [FALSE POSITIVE]
}
int test28() {
bool a = true, b = true, c = true;
int val;
while (a ? b : c)
{
val = 1;
a = false;
c = false;
}
return val; // GOOD [FALSE POSITIVE]
}
int test29() {
bool a, b = true, c = true;
int val;
while ((a && b) || c) // BAD (a is uninitialized)
{
val = 1;
b = false;
c = false;
}
return val; // GOOD [FALSE POSITIVE]
}
int test30() {
int val;
do
{
val = 1;
} while (false);
return val; // GOOD
}
int test31() {
bool loop = true;
bool stop = false;
bool a, b = true, c = true;
int val;
while (loop || false)
{
loop = false;
}
while (!stop)
{
stop = true;
}
while ((a && b) || c) // BAD (a is uninitialized)
{
b = false;
c = false;
}
do
{
} while (false);
return val; // BAD
}
int test32() {
int val;
while (true)
{
}
return val; // GOOD (never reached)
}
int test33() {
int val;
while (val = 1, true) {
return val; // GOOD
}
}