Menu

cppcheck inline suppressions and MISRA add-on

2018-10-19
2020-05-14
  • Shin Byorun

    Shin Byorun - 2018-10-19

    I would like to inquire how to perform inline code suppressions for MISRA rules when using misra.py on a dump file?

    I tried the following but the suppressions are not added in the "Suppressed Rules List":

    // cppcheck-suppress 15.6
    // cppcheck-suppress MISRA_15.6
    // cppcheck-suppress misra_15.6
    // cppcheck-suppress MISRA_15_6
    // cppcheck-suppress MISRA.15.6

     
    • Bassam Abdul-Baki

      The manual says to do the following:

      Using Cppcheck addons
      Currently there are two steps to use an addon:
      1. Run Cppcheck to generate dump files
      2. Run the addon on the dump files
      The --dump flag is used to generate dump files. To generate a dump file for every source file in the
      foo/ folder:
      cppcheck --dump foo/
      To run a addon script on all dump files in the foo/ folder:
      python addon.py foo/*.dump

      To suppress a MISRA rule, use:
      python misra.py --suppress-rules 15.1,11.3,20.13 ...

      You were using cppcheck directly on the dump files.

      Only parsing the suppressed rules uses:
      ^(misra|MISRA)_._.

       
  • Daniel Marjamäki

    I am not sure. Maybe inline suppressions are not added in the dump file. That is not by intention.

    I created https://trac.cppcheck.net/ticket/8804

     
  • Daniel Marjamäki

    it seems to work for me. I tried with:

    // cppcheck-suppress misra-c2012-16.1
    void f();
    

    when the dump file is generated you need to use --inline-suppr.

     
  • Richard Smith

    Richard Smith - 2018-11-06

    I never did any testing with inline suppressions. Let me know if they don't work and I'll see if I can figure out why.
    Note the above rule (misra-c2012-16.1) will not be parsed corrected by the misra.py code as the rule number needs to be immediately after the 'misra' prefix.

     
  • Richard Smith

    Richard Smith - 2019-07-09

    Thanks for the testing. I'm not sure when I'll have time to look at this. Do you know any python? You can use the --show-suppressed-rules argument to misra.py to make it dump the parsed suppression list.
    To check the incomming items from the dump file you will have to add some debugging to the parseSuppressions() method. You will need to print out the values coming in from
    for each in self.dumpfileSuppressions

    And then debug if the parser is not pickingup the inline suppression values correctly.

     
  • Riccardo Biasini

    yes, I can attempt some debug when I'll have some time. Thanks for the hints on where to look.

     
  • Mike Banducci

    Mike Banducci - 2020-05-13

    This issue is still present in v1.90.

    For example, I can induce misra-c2012-15.5:

    int f(int x)
    {
        if (0 == x)
            // cppcheck-suppress misra-c2012-15.5
            return x;
        else
            // cppcheck-suppress misra-c2012-15.5
            return 2*x;
    
        return 0;
    }
    

    In the gui, with the "enable inline suppressions" checked, I still see both errors reported.

    The xml results look like this (I redacted the rules text manually):

    <?xml version="1.0" encoding="UTF-8"?>
    <results version="2">
        <cppcheck version="1.90"/>
        <errors>
            <error id="unmatchedSuppression" severity="information" msg="Unmatched suppression: misra-c2012-15.5" verbose="Unmatched suppression: misra-c2012-15.5" sinceDate="5/13/2020">
                <location file="cppcheck-test\test.cpp" line="5"/>
            </error>
            <error id="unmatchedSuppression" severity="information" msg="Unmatched suppression: misra-c2012-15.5" verbose="Unmatched suppression: misra-c2012-15.5" sinceDate="5/13/2020">
                <location file="cppcheck-test\test.cpp" line="8"/>
            </error>
            <error id="misra-c2012-15.5" severity="style" msg="" verbose="" sinceDate="5/13/2020">
                <location file="cppcheck-test\test.cpp" line="5"/>
            </error>
            <error id="misra-c2012-15.5" severity="style" msg="" verbose="" sinceDate="5/13/2020">
                <location file="cppcheck-test\test.cpp" line="8"/>
            </error>
            <error id="unusedFunction" severity="style" msg="The function &amp;#039;f&amp;#039; is never used." verbose="The function &amp;#039;f&amp;#039; is never used." sinceDate="5/13/2020">
                <location file="cppcheck-test\test.cpp" line="1"/>
            </error>
        </errors>
    </results>
    
     
  • Daniel Marjamäki

    Thanks! I created this trac ticket: https://trac.cppcheck.net/ticket/9723

     

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.