Skip to content

Commit f2e68da

Browse files
committed
CPP: Use dataflow to find wrapped rounding functions.
1 parent 207c4d3 commit f2e68da

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

cpp/ql/src/Likely Bugs/Conversion/LossyFunctionResultCast.ql

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import cpp
13+
import semmle.code.cpp.dataflow.DataFlow
1314

1415
predicate whitelist(Function f) {
1516
exists(string fName |
@@ -52,14 +53,10 @@ predicate whitelistPow(FunctionCall fc) {
5253
predicate whiteListWrapped(FunctionCall fc) {
5354
whitelist(fc.getTarget()) or
5455
whitelistPow(fc) or
55-
exists(ReturnStmt rs |
56-
rs.getEnclosingFunction() = fc.getTarget() and
57-
whiteListWrapped(rs.getExpr())
58-
) or
59-
exists(ReturnStmt rs, Variable v |
60-
rs.getEnclosingFunction() = fc.getTarget() and
61-
rs.getExpr().(VariableAccess).getTarget() = v and
62-
whiteListWrapped(v.getAnAssignedValue())
56+
exists(Expr e, ReturnStmt rs |
57+
whiteListWrapped(e) and
58+
DataFlow::localFlow(DataFlow::exprNode(e), DataFlow::exprNode(rs.getExpr())) and
59+
fc.getTarget() = rs.getEnclosingFunction()
6360
)
6461
}
6562

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,5 @@ void test3()
127127
{
128128
int i = myRound1(1.5); // GOOD
129129
int j = myRound2(2.5); // GOOD
130-
int k = myRound3(3.5); // GOOD [FALSE POSITIVE]
130+
int k = myRound3(3.5); // GOOD
131131
}

0 commit comments

Comments
 (0)