Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11013b0

Browse files
committed
CPP: Add a few more test cases.
1 parent 82e5456 commit 11013b0

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

cpp/ql/test/query-tests/Likely Bugs/Conversion/LossyFunctionResultCast/ImplicitDowncastFromBitfield.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
| test.cpp:40:13:40:21 | call to getDouble | Return value of type double is implicitly converted to int here. |
55
| test.cpp:43:6:43:12 | call to getMyLD | Return value of type long double is implicitly converted to bool here. |
66
| test.cpp:45:13:45:19 | call to getMyLD | Return value of type long double is implicitly converted to int here. |
7+
| test.cpp:97:10:97:12 | call to pow | Return value of type double is implicitly converted to int here. |
8+
| test.cpp:99:10:99:12 | call to pow | Return value of type double is implicitly converted to int here. |
9+
| test.cpp:101:10:101:12 | call to pow | Return value of type double is implicitly converted to int here. |
10+
| test.cpp:103:10:103:12 | call to pow | Return value of type double is implicitly converted to int here. |
11+
| test.cpp:105:10:105:12 | call to pow | Return value of type double is implicitly converted to int here. |
12+
| test.cpp:118:10:118:16 | call to myRound | Return value of type double is implicitly converted to int here. |

cpp/ql/test/query-tests/Likely Bugs/Conversion/LossyFunctionResultCast/test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,34 @@ void test1()
8686
setPosFloat(round(getDouble()));
8787
}
8888
}
89+
90+
double pow(double x, double y);
91+
92+
int test2(double v, double w, int n)
93+
{
94+
switch (n)
95+
{
96+
case 1:
97+
return pow(2, v); // GOOD [FALSE POSITIVE]
98+
case 2:
99+
return pow(10, v); // GOOD [FALSE POSITIVE]
100+
case 3:
101+
return pow(2.5, v); // BAD
102+
case 4:
103+
return pow(v, 2); // BAD
104+
case 5:
105+
return pow(v, w); // BAD
106+
};
107+
}
108+
109+
double myRound(double v)
110+
{
111+
double result = round(v);
112+
113+
return result;
114+
}
115+
116+
void test3()
117+
{
118+
int i = myRound(1.5); // GOOD [FALSE POSITIVE]
119+
}

0 commit comments

Comments
 (0)