Menu

cppcheck 2.5 - false positive on MISRA rule 8.2 when passing array pointer

khouri
2021-07-20
2021-07-20
  • khouri

    khouri - 2021-07-20

    In the following example, cppcheck (2.5) produces a warning for violating MISRA rule 8.2 at the first line of source code. However, the prototype is correct and all parameters are named. The uncommon syntax of declaring a "pointer to array 2 of int" seems to be triggering a false positive.

    static void example_func(int (*param1)[2], int param2);
    
    static void example_func(int (*param1)[2], int param2)
    {
        (void)param1; // unused
        (void)param2; // unused
    }
    
    
    int main(void)
    {
        example_func();
        return 0;
    }
    

    To reproduce, run cppcheck (version 2.5) as follows:

    cppcheck --enable=all --addon=misra.py file.c

    This should produce the following output:

    Checking file.c ...
    file.c:2:25: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-8.2]
    static void example_func(int (*param1)[2], int param2);
    

    Furthermore, cppcheck doesn't report a warning that no parameters are actually passed in main to example_func, but perhaps that is related to the error at hand.

     
  • Georgiy Komarov

    Georgiy Komarov - 2021-07-20

    Thanks!
    The problem is in Cppcheck itself. I created the following ticket: https://trac.cppcheck.net/ticket/10376 .

     
  • khouri

    khouri - 2021-07-20

    Thanks for the quick response!
    Is this the best place and format to report issues, or would it be better to request an account on Trac sometime?

     
  • Georgiy Komarov

    Georgiy Komarov - 2021-07-20

    It's okay to report some bugs here. But for convenience, you can ask for Trac account from Daniel, as described here.

     

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.