LRESULT CUserDlgHelper::SetSpinner(WPARAM wParam, LPARAM lParam)
{
listCDIt it = GetItem((int)wParam);
auto pdVal = reinterpret_cast<const double*="">(lParam);
if ((it != m_items.end()) && pdVal) // if all OK
{
const double dVal = </const>pdVal;
if (dVal != 0)
{
it->SetUseSpin(true); // Set up the control info
if (it->GetType() == DLG_REAL)
it->SetSpinStep(dVal);
else // make sure spin step is OK
{
int nStep = (int)dVal;
if (nStep == 0) // for integer controls <<-CWE: 570 here
nStep = 1;
it->SetSpinStep(nStep);
}
}
else
it->SetUseSpin(false);
}
return0;
}
This code reports:
CWE: 570
Condition 'nStep==0' is always false
The checker is assuming that assignment of a non-zero double to an integer yields a non-zero result. COunter example: int i = 0.5;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
LRESULT CUserDlgHelper::SetSpinner(WPARAM wParam, LPARAM lParam)
{
listCDIt it = GetItem((int)wParam);
auto pdVal = reinterpret_cast<const double*="">(lParam);
if ((it != m_items.end()) && pdVal) // if all OK
{
const double dVal = </const>pdVal;
if (dVal != 0)
{
it->SetUseSpin(true); // Set up the control info
if (it->GetType() == DLG_REAL)
it->SetSpinStep(dVal);
else // make sure spin step is OK
{
int nStep = (int)dVal;
if (nStep == 0) // for integer controls <<-CWE: 570 here
nStep = 1;
it->SetSpinStep(nStep);
}
}
else
it->SetUseSpin(false);
}
}
This code reports:
CWE: 570
Condition 'nStep==0' is always false
The checker is assuming that assignment of a non-zero double to an integer yields a non-zero result. COunter example: int i = 0.5;
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/10792