Menu

Oversimplified flow analysis (?)

2023-07-07
2023-07-07
  • Martin Poupě

    Martin Poupě - 2023-07-07

    Hello,
    lets have following code:

    int resolvex(int num);
    int resolvey(int num);
    
    int resolve(int num,int x, int y)
    {
        if(x)
        {
            switch(num)
            {
            case 1:
                return resolvex(num);
            }
        }
    
        if(y)
        {
            return resolvey(num);
        }
    
        if(x)
        {
            return resolvex(num);
        }
        return 0;
    }
    

    Online demo says: [test.cpp:6] -> [test.cpp:20]: (style) Condition 'x' is always false

    However this is not true, assume x == 1, y == 0 but num != 1. In such case the second "if(x)" condition is crucial.
    Best regards
    Martin

     
  • CHR

    CHR - 2023-07-07

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

     

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.