cppcheck如何抑制内联不匹配的抑制?

时间:2016-12-09 16:16:58

标签: c++ static-code-analysis cppcheck

我发现--suppress=unmatchedSuppression仅抑制cppcheck选项中不匹配的抑制类型,但不是不匹配的内联抑制。

这是预期的行为吗?

  

test.c的

  • 第4行错了。应该警告arrayIndexOutOfBounds

  • 第7行没问题。不应警告arrayIndexOutOfBounds

我为这两行提供了内联cppcheck-suppress

  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 }
  

情况1

取消代码中不存在的cstyleCast

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

我被警告(以及其他不相关的警告)

    {li}

    unmatchedSuppression: arrayIndexOutOfBounds test.c line 7(正如预期的那样)

    {li}

    unmatchedSuppression: cstyleCast * line 0(正如预期的那样)

      

    情况2

    与情况1相同,但附加--suppress=unmatchedSuppression选项

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

    我希望以前的unmatchedSuppression警告都会消失。但我还是得到了

      {li} unmatchedSuppression test.c line 7(非预期)

1 个答案:

答案 0 :(得分:3)

我最近发现,来自内联抑制的unmatchedSuppression警告不能被通用--suppress=unmatchedSuppression抑制,也不能仅将该警告ID放在--suppressions-list文件中。你必须用文件名限定它。例如--suppress=unmatchedSuppression:test.c