Menu

False Positive: continue in do while loop

2023-05-17
2023-05-17
  • Yannick HOUDOT

    Yannick HOUDOT - 2023-05-17

    file test.c :


    void main ()
    {
    int i;
    do {
    i = random();

        if( i == 0 )
            continue;
    
    } while(i);
    

    }


    $ /opt/cppcheck-2.10/cppcheck --enable=all test.c
    Checking test.c ...
    test.c:10:13: style: Condition 'i' is always true [knownConditionTrueFalse]
    } while(i);
    ^

    Is it a known issue ?

     
  • CHR

    CHR - 2023-05-17

    Thanks for reporting, it's probably an instance of https://trac.cppcheck.net/ticket/11096

     
  • Yannick HOUDOT

    Yannick HOUDOT - 2023-05-17

    ok, looks like it.
    but the example you just add to the trac ticket reports no false positive, but indeed a real [knownConditionTrueFalse]...

     
  • CHR

    CHR - 2023-05-17

    Thanks, fixed.

     

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.