Menu

fall through cases and infinite loops

2017-07-06
2017-07-06
  • Ali Hussain

    Ali Hussain - 2017-07-06

    Hi,
    I am woundering why cppcheck do't allow to check infinite loops and fallthrough cases. Is their any way i can implement these checks in cppcheck.

     
  • Daniel Marjamäki

    The MISRA addon looks for fallthrough cases. I do not like that checker because whenever the fallthrough is intended you must suppress a false positive with a comment. Therefore this will never be implemented in cppcheck core, but in a addon that is ok.

    About infinite loops. We have "Condition is always true/false" warnings. Are there some cases that are not detected?

     
  • Ali Hussain

    Ali Hussain - 2017-07-19

    With the following code i have used --enable=all , --enable= warning but still not detecting the infinite loop.

    #include <iostream> using namespace std; // starting main int main() { cout << "hello in test of cpp "; for(int i = 0; i<10 ; i++ ){ cout << "in for loop"; } for(int j = 0; j<10 ; ){ cout << "in infinite for loop"; } switch(k){ case 1:{ cout << "hello"; break; } case 2:{ cout << "hello"; } } return 0; }

     

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.