Main Content

Check for and Review Coding Defects and Coding Standard Violations In Polyspace Platform

Using Polyspace® Platform, you can check your C/C++ code for coding defects and violations of various external coding standards such as MISRA C™:2023. Adhering to coding standards can reduce the number of defects and improve the quality of your code.

Polyspace can detect coding rule violations for various standards including MISRA C++:2023, MISRA C:2023, and AUTOSAR C++:14. For a list of supported standards, see Coding Standards.

Configure Defects and Coding Standards

Before you start a Bug Finder analysis, select which defects and coding rules you want to activate. A default analysis activates the default set of Bug Finder defects and no coding rules. In the Polyspace Platform user interface, you configure the defects and coding rules using the Static Analysis tab of Configuration. If you have a checkers activation file (.XML), an analysis configuration file (.pscfg) or a user-defined coding standard (.pschk), you can use these files to configure defects and coding standards for your static analysis. Otherwise, you can create your own configuration.

Use Existing Configuration

If you have an existing configuration, use the configuration in your analysis:

  • Checkers activation file (.XML) or User defined Coding standard (.pschk)— Locate the Defects and Coding Standards node in the Static Analysis tab of the Configuration in the Polyspace Platform user interface. Select the option Use custom checkers file and then specify the path to the .XML or .pschk file in the option Checkers activation file.

  • Configuration file (.pscfg) — Open Configuration in the Polyspace Platform user interface. In the toolstrip, go to the Configuration tab and click Import.

    The Import Button int the toolstrip for importing configuration

    Navigate to the .pscfg file that contains the static analysis configuration.

Create New Configuration

You can configure your defects and coding standard using the Checkers Selection window in the Polyspace Platform user interface.

  1. Select Configuration and locate the Static Analysis tab.

  2. In the Defects and Coding Standards node, select Use custom checkers file.

  3. Open the Checkers Selection window by clicking next to the option Checkers activation file.

    Checkers Selection window showing available defects and coding standards for Bug Finder

In the Checkers Selection window, select the defects and coding rules that you want to activate. You can select predefined set of defects or coding rules:

  • Defects — Polyspace categorizes the Bug Finder defects by their impact on your code. You can select one or more of High, Medium, or Low, which selects the defects with corresponding impacts.

  • Coding rules — Each coding standard categories its coding rules in various categories For example, the MISRA C++:2023 coding standard categorizes its rules into Mandatory, Required, and Advisory categories. These categories are selectable checkboxes in the Checkers Selection window, allowing you to select these categories as predefined sets of coding rules.

You can also create a custom selection of coding rules and defects by manually selecting the coding rules and defects that you want. In the Checkers selection window, the defects and coding standards are on the left pane. On the right pane, select the rules that you want to include in your analysis.

  • When selecting Guidelines > Software Complexity checkers, review their thresholds. If the default thresholds are not acceptable, specify a suitable threshold in the Threshold column. See Check guidelines (-guidelines).

  • When selecting Custom rules, review the Pattern and Convention for the rules. See Check custom rules (-custom-rules).

The Checkers Selection window allows you to search for a specific word in the name of the defect or coding rule by using the Filter field. Use this field to search for coding rules and defect related to specific concepts.

When you save the selection of coding rules and defect, the configuration is saved in an XML file that you can reuse for multiple analyses. 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, specify the path to the file in the field Checkers activation file in the Defects and Coding Standards node.

Alternatively, create user defined coding standard that collects various defects and coding rules into a single standard. See Create User-Defined Coding Standard by Using Polyspace Bug Finder Checkers.

Review Results

After the analysis, the results are listed in the Results pane. Select the Defect results. For more details about opening results in the Polyspace Platform user interface, see Open Polyspace Results in Polyspace Platform User Interface.

Violations of coding standards are indicated in the source code with the icon.

For further steps, see Review Polyspace Bug Finder Results in Polyspace Platform User Interface.

Generate Reports

You can generate reports using one of the available template. To generate a report:

  1. Right click the analysis result and from the context menu, select Open Review.

  2. In the toolstrip, select Report > Run Report.

    Example Coding Standards & Code Metrics pane

    The Run Report dialog opens.

  3. In the Run Report dialog, select a Report Template. For a Bug Finder analysis that checks for defects and coding rule violations, you can select one of these templates:

    • BugFinder — This template creates a report that contains the coding rule violations, defects, their review information, and configuration settings for the Polyspace Platform user interface project.

    • BugFinderSummary — This template creates a report that contains a summary of the results.

    • CodingStandards — This template creates a report that contains only the coding rule violations in your code and omits other results.

  4. Specify Output folder and select Output format.

  5. To generate the report, select Run Report.

For more details about the templates, see Bug Finder and Code Prover report (-report-template).

See Also

| |

Related Topics