Menu

False Positive MISRA 18.8

Amir
2020-09-24
2020-09-25
  • Amir

    Amir - 2020-09-24

    Hello,
    I'm getting a false positive on the following code:

    static uint32_t setFaultTimer[FAULT_MAX] = {0};
    static uint32_t clearFaultTimer[FAULT_MAX]  ={0};
    

    Error:

    asw\aswFaults.c:103:18: style: Required. Variable-length array types shall not be used [misra-c2012-18.8]
    
                     ^
    asw\aswFaults.c:102:18: style: Required. Variable-length array types shall not be used [misra-c2012-18.8]
    

    Here is the definition of FAULT_MAX:

    typedef enum {
        FAULT_CELL_OVP,
        FAULT_CELL_UVP,
        FAULT_PACK_OVP,
        FAULT_PACK_UVP,
        FAULT_MOD_OTP,
        FAULT_MOD_UTP,
        FAULT_PRECHARGE,
        FAULT_PACK_V,
        FAULT_CONT_WELD,
        FAULT_CHARGE,
        FAULT_DISCHARGE,
        FAULT_THERMISTOR,
        FAULT_CALIBRATION,
        FAULT_MAX
    }Fault_t;
    

    FAULT_MAX is always going to be the same value during runtime, so I think this is a false positive.

    Regards,
    Amir

     
  • Georgiy Komarov

    Georgiy Komarov - 2020-09-25

    Hello, Amir,

    Thanks for reporting this. The MISRA 2012 document doesn't explicitly define this situation, but it seems right for me. C89 standard defines enum members as enumeration contants at ch. 6.4.4.3, and they are always known at compile time.

    I think this should not lead to R18.8 warnings. I will create a ticket when Trac is available.

    Update: I created the ticket https://trac.cppcheck.net/ticket/9913

     

    Last edit: Georgiy Komarov 2020-09-25
  • Amir

    Amir - 2020-09-25

    Thank you!

     
  • Amir

    Amir - 2020-09-25

    BTW when I move the variables from function scope to file scope, the warning disappears.

     
  • Georgiy Komarov

    Georgiy Komarov - 2020-09-25
     

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.