Menu

Possible check miss related to suppressed rules

2021-03-24
2021-03-29
  • Enrique Malras

    Enrique Malras - 2021-03-24

    Hi,

    I am working with cppcheck version 2.4.1 + misra.py addon combined with --inline-suppr option for cppcheck. I am checking a boilerplate.c source code that haves 5 known misra violations.

    I am able to generate the .dump file with the suppressions section, and next output is generated when misra.py parses the .dump file:

    >python misra/misra.py src/boilerplate.c.dump
    Checking src/boilerplate.c.dump...
    Checking src/boilerplate.c.dump, config ...
    
    MISRA rules violations found:
            Undefined: 5
    
    MISRA rules violated:
            misra-c2012-15.5 (-): 1
            misra-c2012-20.1 (-): 4
    

    As can be seen, the rules violation dissapear (as expected) but the total count of violations remain up to 5 (expected to be 0).

    I could review the misra.py code, and it seems that it is missing some check on the reportError() function. I could solve this (at least working in my environment) by adding an extra check (call to cppcheckdata.is_suppressed()) in that function:

    def reportError(self, location, num1, num2):
            ruleNum = num1 * 100 + num2
    
            if self.settings.verify:
                self.verify_actual.append(str(location.linenr) + ':' + str(num1) + '.' + str(num2))
            #EMalras: First statement checks if the rule has been included as 'global suppressed'
            #EMalras: Second statement checks if the rule has been suppressed because has been justified with some 'cppcheck-suppress' tag within the source code
            elif (self.isRuleSuppressed(location.file, location.linenr, ruleNum) or cppcheckdata.is_suppressed(location, '',  'misra-c2012-'+str(num1)+'.'+str(num2))):
                # Error is suppressed. Ignore
                self.suppressionStats.setdefault(ruleNum, 0)
                self.suppressionStats[ruleNum] += 1
                return
            else:
            .......
    

    With this the output become as expected:

    >python misra/misra.py src/boilerplate.c.dump
    Checking src/boilerplate.c.dump...
    Checking src/boilerplate.c.dump, config ...
    

    No output, which means 'no violations'.

    I'm sure it is not the best solution, but I want to share it with you just to let you know about this issue.

    Thanks!

     
  • Daniel Marjamäki

    hmm looks pretty reasonable to me.

     

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.