cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

Fix false positive MISRA-C findings

Open avostrik opened this issue 3 years ago • 4 comments

Fix false positive report for rules: 8.2 and 15.2

avostrik avatar Apr 22 '21 13:04 avostrik

Thanks! Could you please add some tests to addons/test/misra/misra-test.c to avoid further regressions?

jubnzv avatar Apr 22 '21 13:04 jubnzv

It seems that the violation of 2.7 rule occurs in the header file. But -verify can't parse the expected suppressions from the header, because it works with rawTokens from the current file. I think we can remove the prototype of test_8_2 function from the header file as a workaround.

jubnzv avatar May 06 '21 08:05 jubnzv

It seems that the violation of 2.7 rule occurs in the header file. But -verify can't parse the expected suppressions from the header, because it works with rawTokens from the current file. I think we can remove the prototype of test_8_2 function from the header file as a workaround.

No, removing header prototype will hide initial issue. I think the check for function definitions with identifier lists have to be reworked, as it also does not work with forward declarations in the same module. E.g.

static int func(int some_arg);

// code in between

int func(int some_arg)
{
   return some_arg;
}

also triggers 8.2, but my fix does not help as it seems no easy way to distinguish token declaration for prototype declaration and definition. I have no idea how to do a quick fix and have no time to dig deep into the issue.

On my internal branch I removed the problematic check completely as we never use obsolete K&R declarations in our code base.

avostrik avatar May 06 '21 08:05 avostrik

@avostrik Got it. I added the ability to handle the suppressions in header files in #3252 to properly test these regressions.

On my internal branch I removed the problematic check completely as we never use obsolete K&R declarations in our code base.

Yes, there are some problems with this rule. I also don't use this check yet.

jubnzv avatar May 07 '21 09:05 jubnzv