Filtering out issues using macros or files
You can suppress macros, files, and directories using an external .sconf file. You can import the configuration files with kwcheck or kwciagent similar to other configuration files. You can also provide the .sconf file while running kwbuildproject with the --exclude-issues option, or import it from portal while running a connected project.
You can suppress issues using multiple suppression configurations by adding all of them to the same .sconf file. You can also provide multiple .sconf files.
Sample .sconf file
Below is an example of a typical .sconf file you can pass through the methods above to suppress particular issues:
{ "issue_suppressions": [ { "kind": "macro", "name": "MAP_FAILED", "issue_codes" : [ "MISRA.CAST.VOID_PTR_TO_INT.2012" ], "filter": true } , { "kind": "file", "name": "dir1/file.cpp", "all_issue_codes": false, "filter": true }, { "kind": "directory", "name": "dir2", "all_issue_codes": true, "filter": true } ] }
You should provide either all_issue_codes = true/false or a list of issue codes with issue_codes to specify which issues you want to filter. If the filter is false for any particular issue, then the suppression is skipped.
{ "issue_suppressions": [ { "kind": "macro", "name": "MAP_FAILED", "issue_codes" : [ "MISRA.CAST.VOID_PTR_TO_INT.2012" ], "filter": true } , { "kind": "file", "name": "dir1/file.cpp", "all_issue_codes": false, "filter": true }, { "kind": "directory", "name": "dir2", "all_issue_codes": true, "filter": true } ] }
When we provide suppression configuration for a directory 'dir', and also for a file in the directory 'dir/file.cpp', then the configuration for the file gets preference over the directory, no matter what the order is. For example:
{ "issue_suppressions": [ \{ "kind": "file", "name": "dir/file.cpp", "all_issue_codes": false, "filter": true } , { "kind": "directory", "name": "dir", "all_issue_codes": true, "filter": true } ] }
Since we set all_issue_codes to false for the file, it won't suppress any issues for file.cpp.
As of Klocwork 2022.3, you can also enable optimization when suppressing issues in files and directories. When optimization is enabled, it skips the whole translation unit from that file, but only for path checkers. You can also add comments to the configuration (which are not printed anywhere). For example:
{ "issue_suppressions": [ { "kind": "file", "name": "foo.cpp", "all_issue_codes": true, "filter": true, "allow_optimization": true, "comment": "add comment here" } ] }