Menu

False Positive misra-c2012-9.3

Amir
2021-07-15
2021-07-15
  • Amir

    Amir - 2021-07-15

    Hello,
    I'm seeing a false positive on the following:
    static bool Fault[FAULT_MAX] = {false};

    Error:
    style: Required. Arrays shall not be partially initialized. [misra-c2012-9.3]

    I'm using cppcheck 2.4.1.

     
  • Georgiy Komarov

    Georgiy Komarov - 2021-07-15

    Hello Amir,
    Thanks for the report.

    I can't reproduce this yet. I've created a single file which contains only the line from your message. And it doesn't generate any false positives with Cppcheck 2.4.1 (commit b01c9267f).

    How does FAULT_MAX is defined in your code?

     
  • Amir

    Amir - 2021-07-15

    Here is the definition:

    typedef enum
    {
        FAULT_DIFF_COMM,
        FAULT_HVIL_DISCONNECT,
        FAULT_PCU,
        FAULT_MAX
    } Fault_T;
    
     

    Last edit: Amir 2021-07-15
  • Georgiy Komarov

    Georgiy Komarov - 2021-07-15

    Well, this is not a false positive then.

    You are trying to partially initialize an array of 4 elements, which violates rules 9.3. The MISRA document allows zero initialization only in form = { 0 }, but other forms including = { false } are forbidden. See the previous discussion for more details.

     

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.