The sample code in this section shows a simple but working checker that contains all the components that Coverity requires to run the checker successfully.
include `C/C++`;
checker {
name = "NO_GOTO";
reports = for g in globalset allFunctionCode % gotoStatement :
{
events = [
{
description = "Found a "
+ "goto".formattedAsCode
+ " statement.";
location = g.location;
}
]
}
};
These components of the code are worth noticing:
include- Includes patterns specific to the C or C++ languages, and ensures that the checker tests only C code or C++ code.
nameassignment- Gives a name to the checker. This name will appear in reports of issues found.
forloop-
Scans the target source looking for the
gotostatementpattern. eventslist-
If there is a find, displays an issue report
that shows the
descriptionandlocationspecified here.