Menu

False positive

Greg Smith
2022-02-07
2022-02-08
  • Greg Smith

    Greg Smith - 2022-02-07

    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);
    }

    return 0;
    

    }

    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;

     
  • CHR

    CHR - 2022-02-08

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/10792

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.