Menu

possible false positive

2021-08-31
2021-09-03
  • Alan Braddy

    Alan Braddy - 2021-08-31

    I think the following may be a false positive (or I've misunderstood the MISRA rule):

    When defining an array using a defined constant, cppcheck 2.5 (with MISRA rukles enabled) reports a MISRA error 2012-18.8 (variable length arrays shall not be used) if the definition is ibn an external file.
    e.g.:
    In test.c:

    #include <stdint.h>
    #include "test.h"
    
    //#define ANUMBER   10u
    
    uint16_t globaltest[ANUMBER];
    
    void foo(void)
    {
        uint16_t localtest[ANUMBER];
    
        for (uint16_t index = 0u; index < ANUMBER; index++)
        {
            globaltest[index]= index;
            localtest[index] = index;
        }
    }
    

    with header test.h:

    #define ANUMBER 10u
    

    if the #define ANUMBER 10u is in the local C file (uncomment above) everything is fine, if it's in the header it throws the error.

     

    Last edit: Alan Braddy 2021-08-31
    • Alan Braddy

      Alan Braddy - 2021-08-31

      False alarm - missing include link

       
      • Absol

        Absol - 2021-09-03

        what default paths where cppcheck search includes?

         
        • Daniel Marjamäki

          cppcheck does not have default paths.

           

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.