Menu

False positive: knownConditionTrueFalse

2024-04-30
2024-04-30
  • Pierre DEL PERUGIA

    Hi,

    the following code:

    void f ( unsigned u )
    {
            if ( u > 0 )
            {
                    u--;
                    //
                    if ( u == 0 )
                            g();
            }
    }
    

    produces (or I really don't see how) a false positive:

    g.cpp:7:10: style: Condition 'u==0' is always false [knownConditionTrueFalse]
    if ( u == 0 )
    ^
    g.cpp:3:9: note: Assuming that condition 'u>0' is not redundant
    if ( u > 0 )
    ^
    g.cpp:5:3: note: u is decremented', new value is 4294967295
    u--;
    ^
    g.cpp:7:10: note: Condition 'u==0' is always false
    if ( u == 0 )

    Tested with 2.15 dev (e2fa3cb10).

    Thanks

     
  • CHR

    CHR - 2024-04-30

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

     

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.