Hi,
In the following example, cppcheck 2.7 produces a warning for violating MISRA rule 8.2 on line 3:
#include <stddef.h> static void example_func(size_t num, int param1[num]); int main(void) { int var[] = {1, 2}; example_func(2, var); return 0; } static void example_func(size_t num, int param1[num]) { (void)param1; // unused }
The command launched is the following:
cppcheck --addon=misra.py main.c --suppress=misra-c2012-2.7
And the output is:
Checking main.c ... main.c:3:25: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-8.2] static void example_func(size_t num, int param1[num]); ^
However, if I instead, define a constant as in the code below, the rule 8.2 violation disappears:
#include <stddef.h> #define NUM 2 static void example_func(size_t num, int param1[NUM]); int main(void) { int var[] = {1, 2}; example_func(2, var); return 0; } static void example_func(size_t num, int param1[NUM]) { (void)param1; // unused }
Should it be reported as rule 18.8 violation instead?
Thanks
Hello, Roberto! Yes, it's should be reported as 18.8. We've created a ticket for your issue.
Log in to post a comment.
Hi,
In the following example, cppcheck 2.7 produces a warning for violating MISRA rule 8.2 on line 3:
The command launched is the following:
And the output is:
However, if I instead, define a constant as in the code below, the rule 8.2 violation disappears:
Should it be reported as rule 18.8 violation instead?
Thanks
Last edit: Roberto Geografo 2024-05-07
Hello, Roberto!
Yes, it's should be reported as 18.8. We've created a ticket for your issue.