c++command-linestatic-code-analysisklocwork

Klocwork 9.6 ignore specific checkers only in specified files


We are using Klocwork 9.6 for static code analysis.
To perform an analysis we are using command line tools "kwcheck" command
There are some errors which we just want to filter out.
e.g

(Local) *.cpp:134 UNINIT.STACK.ARRAY.MIGHT (1:Critical) Analyze
'FRUSerial' array elements might be used uninitialized in this function.

(Local) *.cpp:187 INFINITE_LOOP.LOCAL (2:Error) Analyze
Infinite loop

It should be achieved via Klocwork functionality not with output post processing.

Are there any particular Klocwork commands/switches suitable for this?


Solution

  • You can use the kwcheck set-status command to change the status of the defect from Analyze to Ignore or Not a Problem. For example, for a defect listed below:

    1 (Local) foo.cpp:134 UNINIT.STACK.ARRAY.MIGHT (1:Critical) Analyze
    'FRUSerial' array elements might be used uninitialized in this function.
    
    2 (Local) foo.cpp:187 INFINITE_LOOP.LOCAL (2:Error) Analyze
    Infinite loop
    

    The number at the front of each issue above is the ID of the defect, as output from kwcheck run or kwcheck list. So to cite the second defect and set the status to ignore with a comment, you would run:

    kwcheck set-status 2 --status ignore -c "we want to ignore this"
    

    Note that by default kwcheck list displays only defects with a status of Analyze or Fix, so by setting the status to one of these other values the defects will no longer be displayed. If you want to see a list of defects with a particular status, for example the ones you've set to Ignore, you can use the -s or --status option with kwcheck list to specify which status(es) to show.

    If you want to disable specific checkers entirely, you can disable them using the kwcheck disable command. This requires that you have created a local project for the analysis with the kwcheck create command. You can create a local project even as a temporary artifact to customize and control the local analysis and results. It is not required to connect it with a project on the Klocwork server. For example:

    Create a local project:

    kwcheck create
    

    Disable the checkers for defects you don't want to see:

    kwcheck disable UNINIT.STACK.ARRAY.MIGHT INFINITE_LOOP.LOCAL
    

    Run the analysis:

    kwcheck run -b buildspec.out