【问题标题】:cppcheck How to suppress inline unmatched suppression?cppcheck 如何抑制内联不匹配的抑制?
【发布时间】:2017-04-25 04:18:49
【问题描述】:

我发现--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

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

  1. unmatchedSuppression: arrayIndexOutOfBounds in test.c line 7(如预期)

  2. unmatchedSuppression: cstyleCast in * line 0(如预期)

情况2

与情况 1 相同,但有额外的 --suppress=unmatchedSuppression 选项

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

我希望之前的两个 unmatchedSuppression 警告都会消失。但我仍然得到

  1. unmatchedSuppression in test.c line 7(不期望)

【问题讨论】:

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


    【解决方案1】:

    我最近发现,来自内联抑制的unmatchedSuppression 警告无法通过通用--suppress=unmatchedSuppression 或仅将该警告ID 放在--suppressions-list 文件中来抑制。您必须使用文件名对其进行限定。例如--suppress=unmatchedSuppression:test.c

    【讨论】:

      猜你喜欢
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      相关资源
      最近更新 更多