Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

Getting started with kwcheck for C/C++

Getting started with kwcheck for C/C++

kwcheck is a desktop analysis tool for C/C++ and Java developers using IDEs and text editors that aren't supported by Klocwork in the form of an IDE plug-in. You can also try the GUI tool Klocwork Desktop.

Switch to kwcheck for Java

Set up a local project

Set up a local project and connect it to a server project with kwcheck create.

kwcheck create --url http://server2:8080/my_project

Perform this step only the first time. From here on, the steps are the same for the first and subsequent analysis runs.

Capture build settings

To capture build settings, run kwshell from the directory that contains your local project directory (called .kwlp by default).

kwshell

When kwshell starts up, it indicates which Klocwork local project directory (.kwlp) it's using. For example:

Using Klocwork project directory '/space/testing/jlee/my_project/.kwlp'
Running Klocwork Shell ... 

A [kw] prefix is also added to the command-line prompt to indicate that kwshell is running.

Now, build your component. A file must be compiled at least once under kwshell for Klocwork to "see" it. kwshell monitors compile and link commands and creates a build specification.

make
Note: If you need to use settings from the server project in the form of a build specification template (not recommended), do not run kwshell. In this case, you may see a message indicating that one or more variables need to be defined. To set build specification variables, use kwcheck set-var .

Run the analysis

  1. Analyze your code with kwcheck run.
    kwcheck run
    
  2. Display detected issues with kwcheck list.
    kwcheck list -F detailed
    
    Note: When you run the analysis, any new issues detected are local issues. To see system issues, you can specify the --system option.
    Traceback identifies statements in the source code that contribute to detected issues.
5 (System: 22) /testing/myproj/trees.c:777 ABR Fix
Buffer overflow, array index of 'bl_tree' may be out of bounds. Array 'bl_tree'
of size 39 may use index value(s) 39..65535. Also there are 2 similar errors on
line(s) 777.
* foo.c:760: ...:=tree[0] .dl.len
* foo.c:768: n<=max_code is true
* foo.c:769: ...:=tree[n+1] .dl.len
* foo.c:769: curlen:=nextlen
* foo.c:789: nextlen==0 is false
* foo.c:776: curlen!=prevlen is true
* foo.c:777: The array 'bl_tree' size is 39.
* deflate.h:194: The array 'bl_foo' size is 39.
* foo.c:777: Array 'bl_foo' may use the 39..65535 index.
Current status 'Analyze'

See C and C++ checker reference for documentation on detected issues.

Fix defects and ignore the rest

  1. Fix the real defects.
  2. Re-run the analysis.
    kwcheck run
    
  3. Display detected issues.
    kwcheck list -F detailed
    
    When an issue disappears from the list, it's fixed.
  4. Ignore issues you don't care about with kwcheck set-status.
    kwcheck set-status 23-25,30,32 --status Ignore -c "this is 3rd party software"
    
    Your changes are now visible to other developers, and in Klocwork Static Code Analysis. Your desktop project is also updated with any changes made by other developers. This happens even before another integration build analysis.