File tree Expand file tree Collapse file tree
cpp/ql/test/query-tests/Likely Bugs/Conversion/LossyFunctionResultCast Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ | test.cpp:33:6:33:13 | call to getFloat | Return value of type float is implicitly converted to bool here. |
2+ | test.cpp:35:13:35:20 | call to getFloat | Return value of type float is implicitly converted to int here. |
3+ | test.cpp:38:6:38:14 | call to getDouble | Return value of type double is implicitly converted to bool here. |
4+ | test.cpp:40:13:40:21 | call to getDouble | Return value of type double is implicitly converted to int here. |
5+ | test.cpp:43:6:43:12 | call to getMyLD | Return value of type long double is implicitly converted to bool here. |
6+ | test.cpp:45:13:45:19 | call to getMyLD | Return value of type long double is implicitly converted to int here. |
7+ | test.cpp:78:6:78:11 | call to roundf | Return value of type float is implicitly converted to bool here. |
8+ | test.cpp:80:13:80:18 | call to roundf | Return value of type float is implicitly converted to int here. |
Original file line number Diff line number Diff line change 1+ Likely Bugs/Conversion/LossyFunctionResultCast.ql
Original file line number Diff line number Diff line change 1+
2+ typedef long double MYLD;
3+
4+ bool getBool ();
5+ int getInt ();
6+ float getFloat ();
7+ double getDouble ();
8+ MYLD getMyLD ();
9+ float *getFloatPtr ();
10+ float &getFloatRef ();
11+ const float &getConstFloatRef ();
12+
13+ void setPosInt (int x);
14+ void setPosFloat (float x);
15+
16+ double round (double x);
17+ float roundf (float x);
18+
19+ void test1 ()
20+ {
21+ // simple
22+
23+ if (getBool ())
24+ {
25+ setPosInt (getBool ());
26+ setPosFloat (getBool ());
27+ }
28+ if (getInt ())
29+ {
30+ setPosInt (getInt ());
31+ setPosFloat (getInt ());
32+ }
33+ if (getFloat ()) // BAD
34+ {
35+ setPosInt (getFloat ()); // BAD
36+ setPosFloat (getFloat ());
37+ }
38+ if (getDouble ()) // BAD
39+ {
40+ setPosInt (getDouble ()); // BAD
41+ setPosFloat (getDouble ());
42+ }
43+ if (getMyLD ()) // BAD
44+ {
45+ setPosInt (getMyLD ()); // BAD
46+ setPosFloat (getMyLD ());
47+ }
48+ if (getFloatPtr ())
49+ {
50+ // ...
51+ }
52+ if (getFloatRef ()) // BAD [NOT DETECTED]
53+ {
54+ setPosInt (getFloatRef ()); // BAD [NOT DETECTED]
55+ setPosFloat (getFloatRef ());
56+ }
57+ if (getConstFloatRef ()) // BAD [NOT DETECTED]
58+ {
59+ setPosInt (getConstFloatRef ()); // BAD [NOT DETECTED]
60+ setPosFloat (getConstFloatRef ());
61+ }
62+
63+ // explicit cast
64+
65+ if ((bool )getInt ())
66+ {
67+ setPosInt (getInt ());
68+ setPosFloat ((float )getInt ());
69+ }
70+ if ((bool )getFloat ())
71+ {
72+ setPosInt ((int )getFloat ());
73+ setPosFloat (getFloat ());
74+ }
75+
76+ // explicit rounding
77+
78+ if (roundf (getFloat ())) // [FALSE POSITIVE]
79+ {
80+ setPosInt (roundf (getFloat ())); // [FALSE POSITIVE]
81+ setPosFloat (roundf (getFloat ()));
82+ }
83+ if (round (getDouble ()))
84+ {
85+ setPosInt (round (getDouble ()));
86+ setPosFloat (round (getDouble ()));
87+ }
88+ }
You can’t perform that action at this time.
0 commit comments