sam*_*sam 10 c++ static-code-analysis cppcheck
我发现--suppress=unmatchedSuppression仅抑制 cppcheck 选项中不匹配的抑制类型,但不抑制不匹配的内联抑制。
这是预期的行为吗?
测试.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 }
Run Code Online (Sandbox Code Playgroud)
情况1
Suppress cstyleCast,它在代码中不存在。
cppcheck --inline-suppr --force --enable=all
--xml-version=2 --suppress=cstyleCast test.c
2>cppcheckresults.xml
Run Code Online (Sandbox Code Playgroud)
我收到警告(以及其他不相关的警告)
unmatchedSuppression: arrayIndexOutOfBounds在test.c line 7(如预期)
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
Run Code Online (Sandbox Code Playgroud)
我希望之前的两个unmatchedSuppression警告都会消失。但我仍然得到
unmatchedSuppression在test.c line 7(非预期)我最近发现,unmatchedSuppression来自内联抑制的警告无法通过通用--suppress=unmatchedSuppression或仅将该警告 ID 放入--suppressions-list文件中来抑制。您必须使用文件名来限定它。例如--suppress=unmatchedSuppression:test.c。
| 归档时间: |
|
| 查看次数: |
11009 次 |
| 最近记录: |