Menu

Rule missing in "Cppcheck - MISRA C 2012 Compliance"?

2019-02-21
2019-02-21
  • Jeroen Doggen

    Jeroen Doggen - 2019-02-21

    Rule 9.1 is not marked as 'supported' on the page:
    http://cppcheck.sourceforge.net/misra.php

    The following code generates an error that is detected by cppcheck:

    void misra_9_1(void) {
        int unknown_value1;
        int unknown_value2;
    
        if (unknown_value1 == 0) { // detected as [uninitvar]
            unknown_value1++;
            int sum= unknown_value1 + unknown_value2; // detectedas[uninitvar]
        }
    }
    
     

    Last edit: Jeroen Doggen 2019-02-21
  • versat

    versat - 2019-02-21

    I guess uninitvar was not made especially for the Misra checker and is therefore missing.
    It does not find all problems yet.
    In the Misra document it says that jumping over initializations is also forbidden.
    But Cppcheck does not warn for such code:
    misra9.1.c

    #include <stdio.h>
    
    int main()
    {
        goto label1;
        int x = 1;
    label1:
        printf("%d", x + 1);
        return 0;
    }
    

    gcc seems to initialize x to 0, but one can not rely on this i guess:

    $ gcc -o misra9.1 misra9.1.c
    
    $ ./misra9.1
    1
    
     

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.