Menu

False Positive MISRA 18.8

Amir
2020-05-26
2020-05-30
  • Amir

    Amir - 2020-05-26

    Hello,

    I'm getting a false positive on rule 18.8. Here is what I'm seeing:

    ealPcuComm.c:

    #include "mcalUartApi.h"
    
    void Eal_PcuCommManager(void)
    {
        static PcuCommState_t pcuCommState = EAL_PCUCOMM_INIT;
        static uint32_t sendMsgCnt = 0;
        uint16_t rtn = 1;
        uint8_t sendMsg[DIFF_UART_MSG_SIZE] = {'\0'};
    ...
    ...
    

    mcalUartApi.h:

    #define DIFF_UART_MSG_SIZE (12U)

    I'm getting a false positive on:
    uint8_t sendMsg[DIFF_UART_MSG_SIZE] = {'\0'};

    Error:
    eal\ealPcuComm.c:53:10: style: Required. Variable-length array types shall not be used [misra-c2012-18.8]

     

    Last edit: Amir 2020-05-26
  • Daniel Marjamäki

    I spontaneosly wonder if you could have a preprocessing problem. If I copy/paste your code here I do not get this warning. If I comment out the define then the warning is shown. Does the warning go away if you replace DIFF_UART_MSG_SIZE with (12U) in your code?

     
  • Amir

    Amir - 2020-05-27

    Yes the warning does go away. But cppcheck doesn't use the preprocessor, correct? I can compile just find, my preprocessor is finding DIFF_UART_MSG_SIZE. But cppcheck doesn't seem to be finding it?

    Here is misra.json:

    {
        "script": "misra.py",
        "args": [
            "--rule-texts=../cppcheck/misra_rules.txt",
            "--suppress-rules 17.8"
        ]
    }
    

    Here is cppcheck command I'm using:
    cppcheck -rp --inline-suppr --addon=..\cppcheck\misra.json ..\Sources -I ..\BCC

    Regards,
    Amir

     
  • Daniel Marjamäki

    cppcheck preprocess the code. does it show some related warnings if you run: cppcheck --check-config ..\Sources -I..\BCC.

     
  • Amir

    Amir - 2020-05-28

    Hi Daniel,

    Looks like cppcheck was not finding the header files. I've added the -I option for all the places to look for the .h files and it works now. Thanks for the help!

    I'm curious, does the -I option search recursively through sub-directories?

    Regards,
    Amir

     
  • Daniel Marjamäki

    I've added the -I option for all the places to look for the .h files and it works now.

    Great!

    I'm curious, does the -I option search recursively through sub-directories?

    No. We have talked about such behavior. It would be convenient. Well the problem is if you include "foo.h" and there are both "path1/foo.h" and "path2/foo.h".

     
  • Amir

    Amir - 2020-05-28

    Good point, thanks for all the help, cppcheck has proven to be much easier to use than other paid options I've looked at for MISRA. Donation coming your way.

    EDIT: How can I donate to your project?

     

    Last edit: Amir 2020-05-28
  • Daniel Marjamäki

    How can I donate to your project?

    I believe the best options are either:
    * You can sponsor cppcheck contributors. Me: http://github.com/danmar , not sure if anybody else has that option.
    * You can sponsor future kickstarter projects. Do you want that I send you email when I create a Kickstarter project?

     

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.