mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
CPP: Fix false positive.
This commit is contained in:
@@ -10,11 +10,30 @@
|
||||
*/
|
||||
import cpp
|
||||
|
||||
predicate whitelist(string fName) {
|
||||
fName = "ceil" or
|
||||
fName = "ceilf" or
|
||||
fName = "ceill" or
|
||||
fName = "floor" or
|
||||
fName = "floorf" or
|
||||
fName = "floorl" or
|
||||
fName = "nearbyint" or
|
||||
fName = "nearbyintf" or
|
||||
fName = "nearbyintl" or
|
||||
fName = "rint" or
|
||||
fName = "rintf" or
|
||||
fName = "rintl" or
|
||||
fName = "round" or
|
||||
fName = "roundf" or
|
||||
fName = "roundl" or
|
||||
fName = "trunc" or
|
||||
fName = "truncf" or
|
||||
fName = "truncl"
|
||||
}
|
||||
|
||||
from FunctionCall c, FloatingPointType t1, IntegralType t2
|
||||
where t1 = c.getTarget().getType().getUnderlyingType() and
|
||||
t2 = c.getActualType() and
|
||||
c.hasImplicitConversion() and
|
||||
not c.getTarget().getName() = "ceil" and
|
||||
not c.getTarget().getName() = "floor" and
|
||||
not c.getTarget().getName() = "round"
|
||||
not whitelist(c.getTarget().getName())
|
||||
select c, "Return value of type " + t1.toString() + " is implicitly converted to " + t2.toString() + " here."
|
||||
|
||||
@@ -4,5 +4,3 @@
|
||||
| test.cpp:40:13:40:21 | call to getDouble | Return value of type double is implicitly converted to int here. |
|
||||
| test.cpp:43:6:43:12 | call to getMyLD | Return value of type long double is implicitly converted to bool here. |
|
||||
| test.cpp:45:13:45:19 | call to getMyLD | Return value of type long double is implicitly converted to int here. |
|
||||
| test.cpp:78:6:78:11 | call to roundf | Return value of type float is implicitly converted to bool here. |
|
||||
| test.cpp:80:13:80:18 | call to roundf | Return value of type float is implicitly converted to int here. |
|
||||
|
||||
@@ -75,9 +75,9 @@ void test1()
|
||||
|
||||
// explicit rounding
|
||||
|
||||
if (roundf(getFloat())) // [FALSE POSITIVE]
|
||||
if (roundf(getFloat()))
|
||||
{
|
||||
setPosInt(roundf(getFloat())); // [FALSE POSITIVE]
|
||||
setPosInt(roundf(getFloat()));
|
||||
setPosFloat(roundf(getFloat()));
|
||||
}
|
||||
if (round(getDouble()))
|
||||
|
||||
Reference in New Issue
Block a user