Menu

false-postive: knownConditionTrueFalse

2021-06-24
2021-06-25
  • Tobias Mark

    Tobias Mark - 2021-06-24

    Version: 2.4.1
    Example:

    #include <stdlib.h>
    int main(int argc, char *argv[]) {
        int x = atoi(argv[1]);
        if(x) {
            if(x == 1)
                ;
            else
                ;
        }
    }
    

    =>

    /tmp/test.c:5:7: style: Condition 'x==1' is always true [knownConditionTrueFalse]
     if(x == 1)
          ^
    /tmp/test.c:4:8: note: Assuming condition 'x' is true
        if(x) {
           ^
    /tmp/test.c:5:7: note: Condition 'x==1' is always true
     if(x == 1)
    

    Sry if this is already reported there are a lot of threads for knownConditionTrueFalse; i did not check all :)

     
  • Daniel Marjamäki

    Thanks! I can reproduce. I have created ticket https://trac.cppcheck.net/ticket/10323

     
  • Tobias Mark

    Tobias Mark - 2021-06-25

    This seems to be similar:

    int func(const char *inp) {
        if(*inp) {
            if(*inp != '.') {}
        }
    }
    
     
    • Daniel Marjamäki

      Thanks! Yes it looks similar.

       

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.