Menu

MISRA rule 3.1 comments may be too restrictive

Rob Gordon
2018-09-04
2018-09-08
  • Rob Gordon

    Rob Gordon - 2018-09-04

    HI! First of all, thank you for implementing MISRA C checks in cppcheck. We just started applying these checks to our code as a request from a customer. My past experience has shown that most of these checks will provide real benefit and I have seen/fixed many of them in my career.

    It appears that the way rule 3.1 is applied by cppcheck is too restrictive (cppcheck 1.84). Granted, I believe the rule needs some clarification by the committee. The example code given:

    x=y // /* non-compliant
     +x
       // */  
     ;  
     //// should be compliant?
    

    The first sequence of // / is reported as non-compliant by cppcheck, good.
    The second sequence of //
    / is not reported but is not explicitly addressed by MISRA, not an issue right now.
    But the third sequence (added by me for testing) is multiple // sequences together, ie ////. cppcheck complains that these are non-compliant. But there is a stated exception for this in rule 3.1. As a comparison, we have access to the Altium TASKING compiler and it allows the multiple // sequence.

    I believe cppcheck should address the exception stated in the MISRA doc. An updated check for the misra.py script would look like:

    def misra_3_1(rawTokens):
        for token in rawTokens:
            if token.str.startswith('/*'):
                if '//' in token.str[2:] or '/*' in token.str[2:]:
                    reportError(token, 3, 1)
            elif token.str.startswith('//'):
                if '/*' in token.str[2:]:
                    reportError(token, 3, 1)
    

    Cheers,
    Rob

     
  • Daniel Marjamäki

    Thanks! I agree. I made a fix for this.

     

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.