mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
CPP: Add test cases.
This commit is contained in:
@@ -5,3 +5,8 @@
|
||||
| test.cpp:48:2:48:26 | if (...) ... | Function g7 should return a value of type MyValue but does not return a value here |
|
||||
| test.cpp:74:1:76:1 | { ... } | Function g10 should return a value of type second but does not return a value here |
|
||||
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second but does not return a value here |
|
||||
| test.cpp:103:2:103:17 | ExprStmt | Function g13 should return a value of type int but does not return a value here |
|
||||
| test.cpp:108:2:111:2 | if (...) ... | Function g14 should return a value of type int but does not return a value here |
|
||||
| test.cpp:110:3:110:18 | ExprStmt | Function g14 should return a value of type int but does not return a value here |
|
||||
| test.cpp:120:3:120:18 | ExprStmt | Function g15 should return a value of type int but does not return a value here |
|
||||
| test.cpp:134:2:134:36 | ExprStmt | Function g16 should return a value of type int but does not return a value here |
|
||||
|
||||
@@ -62,3 +62,25 @@ void exit(int status);
|
||||
int f10() {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int f11(int x)
|
||||
{
|
||||
if (x < 10)
|
||||
{
|
||||
return x;
|
||||
} else {
|
||||
f10(); // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
int f12(int x)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
// ...
|
||||
|
||||
if (x == 10) return 1; // GOOD
|
||||
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,3 +92,44 @@ void instantiate()
|
||||
g11<int>();
|
||||
g12<int>();
|
||||
}
|
||||
|
||||
void myThrow(const char *error)
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
|
||||
int g13()
|
||||
{
|
||||
myThrow("fail"); // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
|
||||
int g14(int x)
|
||||
{
|
||||
if (x < 10)
|
||||
{
|
||||
myThrow("fail"); // BAD (doesn't always throw)
|
||||
}
|
||||
}
|
||||
|
||||
int g15(int x)
|
||||
{
|
||||
if (x < 10)
|
||||
{
|
||||
return x;
|
||||
} else {
|
||||
myThrow("fail"); // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
}
|
||||
|
||||
void myConditionalThrow(bool condition, const char *error)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
int g16(int x)
|
||||
{
|
||||
myConditionalThrow(x < 10, "fail"); // BAD (doesn't always throw)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user