mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-11 12:07:23 +01:00
fix(CodeQL): float comparison alerts
This commit is contained in:
@@ -381,6 +381,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
static const std::string MULTI_INSERT;
|
static const std::string MULTI_INSERT;
|
||||||
static const std::string MULTI_SELECT;
|
static const std::string MULTI_SELECT;
|
||||||
|
static const float EPSILON_FLOAT;
|
||||||
|
static const double EPSILON_DOUBLE;
|
||||||
|
|
||||||
Poco::Data::Session* _pSession;
|
Poco::Data::Session* _pSession;
|
||||||
Poco::Data::Session* _pEncSession;
|
Poco::Data::Session* _pEncSession;
|
||||||
|
|||||||
@@ -291,6 +291,10 @@ const std::string SQLExecutor::MULTI_SELECT =
|
|||||||
"SELECT * FROM Test WHERE First = '5';";
|
"SELECT * FROM Test WHERE First = '5';";
|
||||||
|
|
||||||
|
|
||||||
|
const float SQLExecutor::EPSILON_FLOAT = 1e-5f;
|
||||||
|
const double SQLExecutor::EPSILON_FLOAT = 1e-9;
|
||||||
|
|
||||||
|
|
||||||
SQLExecutor::SQLExecutor(const std::string& name, Poco::Data::Session* pSession, Poco::Data::Session* pEncSession, bool numberedPlaceHolders):
|
SQLExecutor::SQLExecutor(const std::string& name, Poco::Data::Session* pSession, Poco::Data::Session* pEncSession, bool numberedPlaceHolders):
|
||||||
CppUnit::TestCase(name),
|
CppUnit::TestCase(name),
|
||||||
_pSession(pSession),
|
_pSession(pSession),
|
||||||
@@ -418,7 +422,7 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c
|
|||||||
assertTrue (pool.available() == 4);
|
assertTrue (pool.available() == 4);
|
||||||
assertTrue (pool.dead() == 0);
|
assertTrue (pool.dead() == 0);
|
||||||
assertTrue (pool.allocated() == pool.used() + pool.idle());
|
assertTrue (pool.allocated() == pool.used() + pool.idle());
|
||||||
Session s1(pool.get());
|
Session ss1(pool.get());
|
||||||
|
|
||||||
try { pool.setFeature("f1", true); fail ("setting an unsuported feature must fail", __LINE__, __FILE__); }
|
try { pool.setFeature("f1", true); fail ("setting an unsuported feature must fail", __LINE__, __FILE__); }
|
||||||
catch (Poco::InvalidAccessException&) { }
|
catch (Poco::InvalidAccessException&) { }
|
||||||
@@ -1297,7 +1301,7 @@ void SQLExecutor::floats()
|
|||||||
failmsg (__func__);
|
failmsg (__func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue (ret == data);
|
assertTrue (std::fabs(ret - data) < EPSILON_FLOAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1331,7 +1335,7 @@ void SQLExecutor::doubles()
|
|||||||
failmsg (__func__);
|
failmsg (__func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue (ret == data);
|
assertTrue (std::fabs(ret - data) < EPSILON_DOUBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2943,16 +2947,16 @@ void SQLExecutor::internalExtraction()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//this is what most drivers will return
|
//this is what most drivers will return
|
||||||
int i = rset.value<int>(0,0);
|
int ii = rset.value<int>(0,0);
|
||||||
assertTrue (4 == i);
|
assertEqual (4, ii);
|
||||||
}
|
}
|
||||||
catch(BadCastException&)
|
catch(BadCastException&)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//this is for Oracle
|
//this is for Oracle
|
||||||
double i = rset.value<double>(0,0);
|
double d = rset.value<double>(0,0);
|
||||||
assertTrue (4 == int(i));
|
assertTrue (4, int(d));
|
||||||
}
|
}
|
||||||
catch(BadCastException&)
|
catch(BadCastException&)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -770,7 +770,7 @@ void SQLExecutor::bareboneODBCMultiResultTest(const std::string& dbConnString,
|
|||||||
|
|
||||||
assertTrue (one++ == chr[0]);
|
assertTrue (one++ == chr[0]);
|
||||||
assertTrue (two++ == second);
|
assertTrue (two++ == second);
|
||||||
assertTrue (three == third);
|
assertTrue (std::fabs(three - third) < 1e-6f);
|
||||||
three += 1.0;
|
three += 1.0;
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
|
|||||||
Reference in New Issue
Block a user