Menu

False positive for MISRA-C:2012 Rule 15.7

2019-04-24
2019-04-26
  • Grahame White

    Grahame White - 2019-04-24

    Using the MISRA-C:2012 plugin I'm seeing a number of, what look to me to be false positive, warnings.

    The rule states that all if ... else if constructs should be terminated with an else, using the following example I don't believe that there should be a warning, however one does get raised.

    void SomeFunction(void)
    {
        if (true)
        {        
            SomeFunction();
        }
        else
        {
            if (false)
            {
                SomeFunction();
            } // Should this really fail here?
        }
    }
    

    I'm using cppcheck 1.87 via the GUI.

    On the subject of this particular MISRA-C rule I also feel that the amplification is not being taken into consideration which calls for the terminating else to contain at least one side effect (e.g. some code / function call) or a comment.

     
  • Richard Smith

    Richard Smith - 2019-04-24

    Hi, I've had the same issue in our code base but I haven't been able to re-produce it with a more complex test case. The current simple test case passes. If you can produce a good test case then please add that to the bug.

    https://trac.cppcheck.net/ticket/8657

     
  • Grahame White

    Grahame White - 2019-04-24

    I don't have an account for the bugtracker, so I'll attach my sample code, along with screenshot of it failing here.

    This sample fails 100% of the time for me.

    Looking over my production code that has these failures it only appears that the first if statement inside the else clause triggers a false positive.

     
  • Richard Smith

    Richard Smith - 2019-04-25

    Thanks for the test case. Unfortunatly, that is not very different than what is already in the test cases.
    See void misra_15_7()
    in ./addons/test/misra-test.c
    and it passes there.

    There seems to be some code context specific thing that creates the false positive.

     
  • Richard Smith

    Richard Smith - 2019-04-25

    I stand corrected. If I add your code into the misra-test.c it fails. Perfect! Now we have another test case. Thank you

     
  • Grahame White

    Grahame White - 2019-04-26

    You're welcome, glad you found it helpful.

     

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.