Menu

new knownCondition-FPs with mixed-up condition

Martin
2021-08-20
2021-08-20
  • Martin

    Martin - 2021-08-20

    Hi,

    after the latest commit
    https://github.com/danmar/cppcheck/commit/e62cdbb6648248e6008039bdfd8c7faf02875431
    new FPs show up like:

    void foo()
    {
          auto referenceTime = a.getUnixTimestamp();
          auto triggerTime   = b.getUnixTimestamp();
             if(triggerTime < referenceTime)
             {
                auto diff = referenceTime - triggerTime;
                if(diff < 1)
                {
                   bar();
                }
             }
    }
    

    ->

    /home/user/Desktop/21-08-20.cpp:8:21: style: Condition 'diff<1' is always true [knownConditionTrueFalse]
                if(diff < 1)
                        ^
    /home/user/Desktop/21-08-20.cpp:5:25: note: Assuming that condition 'triggerTime<referenceTime' is not redundant
             if(triggerTime < referenceTime)
                            ^
    /home/user/Desktop/21-08-20.cpp:7:39: note: Assignment 'diff=referenceTime-triggerTime', assigned value is less than 0
                auto diff = referenceTime - triggerTime;
                                          ^
    /home/user/Desktop/21-08-20.cpp:8:21: note: Condition 'diff<1' is always true
                if(diff < 1)
                        ^
    /home/user/Desktop/21-08-20.cpp:1:0: style: The function 'foo' is never used. [unusedFunction]
    
    ^
    

    I think the finding should be 'diff<1' is always false, rather than true.

    Could you please check?

    Thanks,
    Martin

     
  • Paul Fultz

    Paul Fultz - 2021-08-20
     

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.