fix(CodeQL): float comparison alerts

This commit is contained in:
Alex Fabijanic
2025-12-07 23:59:47 -06:00
parent 32633b572f
commit 2a457f30e8
3 changed files with 14 additions and 8 deletions

View File

@@ -381,6 +381,8 @@ public:
private:
static const std::string MULTI_INSERT;
static const std::string MULTI_SELECT;
static const float EPSILON_FLOAT;
static const double EPSILON_DOUBLE;
Poco::Data::Session* _pSession;
Poco::Data::Session* _pEncSession;

View File

@@ -291,6 +291,10 @@ const std::string SQLExecutor::MULTI_SELECT =
"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):
CppUnit::TestCase(name),
_pSession(pSession),
@@ -418,7 +422,7 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c
assertTrue (pool.available() == 4);
assertTrue (pool.dead() == 0);
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__); }
catch (Poco::InvalidAccessException&) { }
@@ -1297,7 +1301,7 @@ void SQLExecutor::floats()
failmsg (__func__);
}
assertTrue (ret == data);
assertTrue (std::fabs(ret - data) < EPSILON_FLOAT);
}
@@ -1331,7 +1335,7 @@ void SQLExecutor::doubles()
failmsg (__func__);
}
assertTrue (ret == data);
assertTrue (std::fabs(ret - data) < EPSILON_DOUBLE);
}
@@ -2943,16 +2947,16 @@ void SQLExecutor::internalExtraction()
try
{
//this is what most drivers will return
int i = rset.value<int>(0,0);
assertTrue (4 == i);
int ii = rset.value<int>(0,0);
assertEqual (4, ii);
}
catch(BadCastException&)
{
try
{
//this is for Oracle
double i = rset.value<double>(0,0);
assertTrue (4 == int(i));
double d = rset.value<double>(0,0);
assertTrue (4, int(d));
}
catch(BadCastException&)
{

View File

@@ -770,7 +770,7 @@ void SQLExecutor::bareboneODBCMultiResultTest(const std::string& dbConnString,
assertTrue (one++ == chr[0]);
assertTrue (two++ == second);
assertTrue (three == third);
assertTrue (std::fabs(three - third) < 1e-6f);
three += 1.0;
++count;