Edit the stub files
At this stage, we edit the automatically generated checkers.xml
and help.xml
files with the information specific to our new checker.
Edit the checkers.xml file
Edit the checkers.xml
file with the KAST expression:
checkers version="1.3"> <categories> <category name="C and C++"> <category name="Custom checkers"> <error id="CHECK.VAR.SIZE"/> </category> </category> </categories> <checkergroup language="C/C++" api="tree_pattern"> <checker id="CHECK.VAR.SIZE"> <libraries> <library path=""/> </libraries> <error id="CHECK.VAR.SIZE" enabled="true" severity="3" title="Check variable size" message="Assignment with possible loss of data"> <pattern> //ExprStmt / Expr::BinaryExpr [@Op = KTC_OPCODE_ASSIGN] [$expr1:=Left] [$expr2:=Right] [not $expr2.isConstant()] [not $expr1.isPointer() | not $expr2.isArray()] [$size1:=$expr1.getTypesize()] [$size2:=$expr2.getTypesize()] [$size1 > 0] [$size2 > 0] [$size1 < $size2] </pattern> </error> </checker> </checkergroup> </checkers>
In this file, we've replaced the original template data with
- the checker title and the message that the checker will generate during analysis
- the KAST expression in the <pattern> field
Edit the help.xml file
When you create and deploy a checker, the help.xml
file populates Klocwork Documentation and is available through context-sensitive help in Klocwork Static Code Analysis. At minimum, you must provide a description of the issue.