Main Content

Check MISRA C:2004 (-misra2)

Check for violation of MISRA C:2004 rules

Description

Specify whether to check for violation of MISRA C™:2004 rules1 . Each value of the option corresponds to a subset of rules to check.

Set Option

User interface (desktop products only): In your project configuration, the option is on the Coding Standards & Code Metrics node. See Dependencies for other options that you must also enable.

User interface (Polyspace Platform, desktop products only): This option does not exist in the project configuration. Activate checkers by using the options Use custom checkers file and Checkers activation file (-checkers-activation-file).

Command line and options file: Use the option -misra2. See Command-Line Information.

Why Use This Option

Use this option to specify the subset of MISRA C:2004 rules to check for.

After analysis, the Results List pane lists the coding standard violations. On the Source pane, for every coding rule violation, Polyspace® assigns a symbol to the keyword or identifier relevant to the violation.

Settings

Default: required-rules

required-rules

Check required coding rules.

single-unit-rules

Check a subset of rules that apply only to single translation units. These rules are checked in the compilation phase of the analysis.

system-decidable-rules

Check rules in the single-unit-rules subset and some rules that apply to the collective set of program files. The additional rules are the less complex rules that apply at the integration level. These rules can be checked only at the integration level because the rules involve more than one translation unit. These rules are checked in the compilation and linking phases of the analysis.

all-rules

Check required and advisory coding rules.

SQO-subset1

Check only a subset of MISRA C rules. For more information, see Software Quality Objective Subsets (C:2004).

SQO-subset2

Check a subset of rules including SQO-subset1 and some additional rules. For more information, see Software Quality Objective Subsets (C:2004).

from-file

Specify an XML file where you configure a custom selection of checkers for this coding standard. To create a configuration file, click , then select the rules and recommendations you want to check for this coding standard from the right pane of the Checkers selection window. Save the file.

To use or update an existing configuration file, in the Checkers selection window, enter the full path to the file in the field provided or click Browse.

If you set the option to from-file, enable Set checkers by file (-checkers-selection-file).

Dependencies

  • This option is available only if you set Source code language (-lang) to C or C-CPP.

    For projects with mixed C and C++ code, the MISRA C:2004 checker analyzes only .c files.

  • If you set Source code language (-lang) to C-CPP, you can activate a C coding rule checker and a C++ coding rule checker. When you have both C and C++ coding rule checkers active, to avoid duplicate results, Polyspace does not produce the C coding rules found in the linking phase (such as MISRA C:2012 Rule 8.3).

Tips

If you select the option single-unit-rules or system-decidable-rules and choose to detect coding rule violations only, the analysis can complete quicker than checking other rules. For more information, see Coding Rule Subsets Checked Early in Analysis.

Command-Line Information

Use the command -misra2 in the command line to check for violations of MISRA C:2004 rules.

Parameter: -misra2
Value: required-rules | all-rules | SQO-subset1 | SQO-subset2 | single-unit-rules | system-decidable-rules | from-file
Example (Bug Finder): polyspace-bug-finder -sources file_name -misra2 all-rules
Example (Bug Finder Server): polyspace-bug-finder-server -sources file_name -misra2 all-rules

Alternatively, enable all or specific MISRA C:2004 rules through a checkers activation XML file. See Checkers activation file (-checkers-activation-file).

Version History

expand all

R2021b: Use of text format for coding rules file not supported

Since R2019a, the file where you define a custom selection of coding standard checkers uses the XML format. Using a text file for this purpose results in an error. You can save custom selections for all the coding standards that Polyspace supports in the same file.

Desktop interface:

If you have a project that contains custom coding standard selection files in text format, Polyspace automatically updates and consolidates those files into a single XML file. If your project has conflicting configurations that refer to the same custom selection file, the software saves the consolidated coding standard selection for each configuration to separate XML files.

To update your text files to the XML format manually, in the Coding Standards & Code Metrics node of the Configuration pane, click . In the Checkers selection window, select the files then click Save Changes. Polyspace consolidates the files into a single XML files, and saves this file as filename.xml, where filename is the name of the first selected file alphabetically. For instance, if you select foo.conf and bar.conf, they are saved as bar.conf.xml.

Command-line/ IDEs:

In the command-line or in the IDE extensions, using text files as input to -misra2 results in an error. To select a custom selection of MISRA C:2004 rules, use an XML file.

Use the file misra_c_2004_rules.xml as a template to create the XML file where you define a custom selection of coding standard checkers. This template file is in polyspaceroot\polyspace\examples\doc_cxx\coding_standards_XML. Here, polyspaceroot is the root installation folder for the Polyspace products, for instance, C:\Program Files\Polyspace\R2024b. To update your script, see this table

OptionUse Instead
-misra2 "custom_standard.conf"-checkers-selection-file misra_c_2004_rules.xml -misra2 from-file

See:

Note

The XML format of the checker configuration file can change in future releases.

 Example of Configuration File in XML Format


1 MISRA™ and MISRA C are registered trademarks of MIRA Ltd., held on behalf of the MISRA Consortium.