Menu

MISRA check in plugin mode does not seem to work any more

2025-05-06
2025-05-13
  • Kazimierz Król

    Kazimierz Król - 2025-05-06

    Hi, I just updated cppcheck to version 2.13.0 (from 1.90), and it does not report any MISRA violations any more. Using this command:

    cppcheck --addon=misra misra-test.c
    

    misra-test.c is my custom test file with the following contents:

    #include <stdint.h>
    #include "file//.h"
    
    #define TEST 34566l
    
    const char *s41_1 = "\x41g";
    
    int main( const int argc, const char* argv )
    {
        char c[2][2] = { 1, 2, 3, 4 };
        int ret = 10;
    
        /* // */
    
        return ret;
    }
    

    cppcheck version 1.90 reported 5 violations in it, but cppcheck 2.13.0 reports nothing.
    The output is (using -v switch):

    Checking misra-test.c ...
    Defines:
    Undefines:
    Includes:
    Platform:native
    

    Running cppcheck with --dump and then misra.py manually seems to be finding the violations:

    root@1c35d5f5ce4e:/work# cppcheck --dump misra-test.c
    Checking misra-test.c ...
    root@1c35d5f5ce4e:/work# python3 /usr/lib/x86_64-linux-gnu/cppcheck/addons/misra.py -verify misra-test.c.dump
    Checking misra-test.c.dump, config ...
    Not expected: misra-test.c:9 2.7
    Not expected: misra-test.c:9 2.7
    Not expected: misra-test.c:14 3.1
    Not expected: misra-test.c:7 4.1
    Not expected: misra-test.c:5 7.3
    Not expected: misra-test.c:7 8.4
    Not expected: misra-test.c:11 9.2
    Not expected: misra-test.c:3 20.2
    

    But with this I'm unable to use the --xml option of cppcheck, which I need.
    I have both versions of ccpcheck installed in Docker containers, the 1.90 is in Ubuntu 20.04, the 2.13.0 is in Ubuntu 24.04. Both have python of course. Mentioning this just in case, although I don't know why it could be a problem.

     
  • Kazimierz Król

    Kazimierz Król - 2025-05-07

    I have just installed version 2.17.1 from the source, and it's still the same. Am I doing something wrong here? If it was a bug I don't suppose it would go unnoticed for so many releases.

     
  • Oliver Stöneberg

    They are style warnings which are not enabled by default. You need to add --enable=style for them to show. That behavior changed in 2.11 (I do not have an exact commit).

    Strangely I am only seeing 6 MISRA warnings using the official Windows binaries but I am getting 10 MISRA warnings on Linux. That needs looking into.

    It also looks like the performance took a major hit starting with 2.5 or even earlier.

     

    Last edit: Oliver Stöneberg 2025-05-09
  • Kazimierz Król

    Kazimierz Król - 2025-05-13

    Thank you sir, this fixed my problem.
    No manual or guide I could find mentioned this. Perhaps the official manual deserves an update :)

    Regarding the number of found violations, if I call it with just --addon=misra, it will find 7 violations, but when called with --addon=misra-custom.json, where the json file specifies a "rule-texts" file, it will find 10. And all of the new ones are different rules on the same lines as the previously found ones. Also I tried to fix a violation from one line the first output, and then it started detecting the second violation on the same output:

    root@27830908bbb7:/work# cppcheck --addon=misra --enable=style misra-test.c
    Checking misra-test.c ...
    misra-test.c:5:14: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-7.3]
    #define TEST 34566l
                 ^
    root@27830908bbb7:/work# cppcheck --addon=misra-custom.json --enable=style misra-test.c
    Checking misra-test.c ...
    misra-test.c:5:14: style: Do not use lower case 'l' in constants [misra-c2012-7.3]
    #define TEST 34566l
                 ^
    misra-test.c:5:0: style: Avoid unused macros [misra-c2012-2.5]
    #define TEST 34566l
    ^
    // Now I have changed 34566l to 34566L
    root@27830908bbb7:/work# cppcheck --addon=misra --enable=style misra-test.c
    Checking misra-test.c ...
    misra-test.c:5:0: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.5]
    #define TEST 34566L
    ^
    

    So it seems like cppcheck (on Windows) will show max one MISRA violation per line if rule-texts are not provided.

     

    Last edit: Kazimierz Król 2025-05-13

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.