Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cppcheck How to suppress inline unmatched suppression?

I found that --suppress=unmatchedSuppression only suppresses unmatched suppression types in cppcheck options, but NOT unmatched inline suppressions.

Is this the expected behavior?

test.c

  • Line 4 is wrong. It should be warned arrayIndexOutOfBounds

  • Line 7 is okay. It should NOT be warned arrayIndexOutOfBounds

I have inline cppcheck-suppress for both lines.

  1 void f() {
  2     char arr[5];
  3     // cppcheck-suppress arrayIndexOutOfBounds
  4     arr[10] = 0;
  5
  6     // cppcheck-suppress arrayIndexOutOfBounds
  7     const char ok[] = "this line is ok";
  8 }

Situation 1

Suppress cstyleCast, which does NOT exist in code.

 cppcheck --inline-suppr --force --enable=all 
          --xml-version=2 --suppress=cstyleCast test.c 
          2>cppcheckresults.xml

I get warned about (among other irrelevant warnings)

  1. unmatchedSuppression: arrayIndexOutOfBounds in test.c line 7 (as expected)

  2. unmatchedSuppression: cstyleCast in * line 0 (as expected)

Situation 2

Same as situation 1, but with additional --suppress=unmatchedSuppression option

 cppcheck --inline-suppr --force --enable=all 
          --xml-version=2 --suppress=cstyleCast --suppress=unmatchedSuppressiontest.c 
          2>cppcheckresults.xml

I expect both previous unmatchedSuppression warnings to go away. But I still get

  1. unmatchedSuppression in test.c line 7 (NOT expected)
like image 468
kgf3JfUtW Avatar asked Oct 17 '22 21:10

kgf3JfUtW


1 Answers

What I recently found is that an unmatchedSuppression warning from inline suppressions cannot be suppressed by a generic --suppress=unmatchedSuppression or putting just that warning ID in a --suppressions-list file. You have to qualify it with the filename. For example --suppress=unmatchedSuppression:test.c.

like image 167
Kurtis Rader Avatar answered Oct 21 '22 06:10

Kurtis Rader