With Polyspace®, you can check your C/C++ code for violations of coding rules such as MISRA C®:2012 rules. Adhering to coding rules can reduce the number of defects and improve the quality of your code.
Polyspace can detect the violations of these rules:
MISRA C: 2004
MISRA C: 2012
JSF AV C++
AUTOSAR C++14 (Bug Finder only)
CERT® C (Bug Finder only)
CERT C++ (Bug Finder only)
ISO®/IEC TS 17961 (Bug Finder only)
Specify the coding rules through Polyspace analysis options. When you run Bug Finder or Code Prover, the analysis looks for coding rule violations in addition to other checks. You can disable the other checks and look for coding rule violations only.
In the Polyspace user interface (desktop products), the options are on the Configuration pane under the Coding Standards & Code Metrics node.
For C code, use one of these options:
For C++ code, use one of these options:
You can specify a predefined subset of rules, for instance,
mandatory for MISRA C: 2012. These subsets are typically defined by the standard.
You can also define naming conventions for identifiers using regular expressions. See Create Custom Coding Rules.
Instead of the predefined subsets, you can specify your own subset of rules from a coding standard.
User Interface (Desktop Products Only)
Select the coding standard. From the drop-down list for the subset
of rules, select
In the Findings selection window, the coding standard is highlighted on the left pane. On the right pane, select the rules that you want to include in your analysis.
When you save the rule selections, the configuration is saved in an XML file that you can reuse for multiple analyses. The same file contains rules selected for all coding standards. You can reuse this file across multiple projects to enforce common coding standards in a team or organization. To reuse this file in another project in the Polyspace user interface:
Choose a coding standard in the project configuration. From the
drop-down list for the subset of rules, select
Click Edit and browse to the file location.
Alternatively, enter the file name as argument for the option
Set checkers by file
Command Line. With the Polyspace desktop products, you can create a coding standard XML file in
the user interface and then use this file for command-line analysis. Provide
this XML file with the option
Set checkers by file
With the Polyspace Server products, you have to create a coding standard XML from
scratch. Depending on the standard that you want to enable, make a writeable
copy of one of the files in
and turn off rules using entries in the XML file (all rules from a standard
are enabled in the template). Here,
the root installation folder for the Polyspace Server products, for instance,
For instance, to turn off MISRA C: 2012 rule 8.1, use this entry in a copy of the file
<standard name="MISRA C:2012"> ... <section name="8 Declarations and definitions"> ... <check id="8.1" state="off"> </check> ... </section> ... </standard>
To use the XML file for a MISRA C: 2012 analysis in Bug Finder, enter:
polyspace-bug-finder -sources filename -misra3 from-file -checkers-selection-file misra_c_2012_rules.xml
For full list of rule id-s and section names, see:
The XML format of the checker configuration file can change in future releases.
To check for coding standards only:
In Bug Finder, disable checking of defects. Use the option
In Code Prover, check for source compliance only. Use the option
These rules are checked in the later stages of a Code Prover
analysis: MISRA C:2004 rules 9.1, 13.7, and 21.1, and MISRA C:2012 rules 2.2, 9.1, 14.3, and 18.1. If you stop Code
Prover at source compliance checking, the analysis might not find
all violations of these rules. You can also see a difference in
results based on your choice for the option
Verification level (-to). For example, it is possible that Code
Prover suspects in the first pass that a variable may be
uninitialized but proves in the second pass that the variable is
initialized. In that case, you see a violation of MISRA C:2012 Rule 9.1 in the first pass but not in the second
After analysis, you see the coding standard violations on the Results List pane. Select a violation to see further details on the Result Details pane and the source code on the Source pane.
Violations of coding standards are indicated in the source code with the icon.
For further steps, see Review Analysis Results.
You can generate reports using templates that are explicitly defined for coding
standards. Use the
CodingStandards template. This template:
Reports only coding standard violations in your analysis results, and omits other types of results such as defects, run-time errors or code metrics.
Creates a separate chapter in the report for each coding standard. the chapter provides an overview of all violations of the standard and then lists each violation.
To specify a report template, use the option
Bug Finder and Code
Prover report (-report-template).