Skip to content

Commit 207c4d3

Browse files
committed
CPP: Test wrapped rounding functions more thoroughly.
1 parent 4f00229 commit 207c4d3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
| test.cpp:101:10:101:12 | call to pow | Return value of type double is implicitly converted to int here. |
88
| test.cpp:103:10:103:12 | call to pow | Return value of type double is implicitly converted to int here. |
99
| test.cpp:105:10:105:12 | call to pow | Return value of type double is implicitly converted to int here. |
10+
| test.cpp:130:10:130:17 | call to myRound3 | Return value of type double is implicitly converted to int here. |

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,26 @@ int test2(double v, double w, int n)
106106
};
107107
}
108108

109-
double myRound(double v)
109+
double myRound1(double v)
110+
{
111+
return round(v);
112+
}
113+
114+
double myRound2(double v)
110115
{
111116
double result = round(v);
112117

113118
return result;
114119
}
115120

121+
double myRound3(double v)
122+
{
123+
return (v > 0) ? round(v) : 0;
124+
}
125+
116126
void test3()
117127
{
118-
int i = myRound(1.5); // GOOD
128+
int i = myRound1(1.5); // GOOD
129+
int j = myRound2(2.5); // GOOD
130+
int k = myRound3(3.5); // GOOD [FALSE POSITIVE]
119131
}

0 commit comments

Comments
 (0)