Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You can prevent C/C++test from reporting specific static analysis findings by defining suppressions. Suppressions are useful when you generally follow a rule, but decide to ignore specific occurrences of the reported finding. If you do not want to receive findings for any violations of a specific rule, disable the rule in the test configuration.

Info
iconfalse
titleSuppressing false positives in MISRA compliance workflows

If you implement a workflow for achieving compliance with the MISRA standard, you can exclude false positive violations from MISRA Compliance reports created on DTP. When you suppress a violation and specify a reason for suppression that begins with "false positive", the violation will not be included in MISRA Compliance reports. See the DTP User Guide for details about the Parasoft compliance solution.

Defining Suppressions in Source Code

Suppression schemes can be defined in the source code with the syntax specified below

Line Suppression

Line suppression allows for suppressing violations in a single line. The suppression comment must be specified at the end of the line of code

...

<suppression keyword> [<rule category> | <rule category> . <rule id> | <rule category > - <rule severity> | ALL ] <suppression comment>

where the violation occurs, using the following syntax:

Code Block
// parasoft-suppress <rule-id>|<rule-category>|ALL "<suppression comment>"

Examples:

Code Block
int proc1(int i)    

Examples

Code Block
// parasoft-suppress CODSTA "suppress all rules in category CODSTA"

// parasoft-suppress CODSTA.NEAAUTOSAR-A7_1_1-a "suppress rule CODSTA.NEAAUTOSAR-A7_1_1-a violation"
{
// parasoft-suppress CODSTA-1 "suppress all rules in category CODSTA with severity level 1"

// parasoft-suppress ALL "suppress all rules"

 char * m = "msg"; // parasoft-suppress CODSTA FORMAT.MCH JAVADOC-3AUTOSAR-A27_0_4 "suppress all rules in category CODSTA and rule FORMAT.MCH and all rules in category JAVADOC with severity level 3"

Block Suppression

Code Block
<begin suppression keyword> [<rule category> | <rule category> . <rule id> | <rule category > - <rule severity> | ALL ] <suppression comment>

 ..... source code block .....

<end suppression keyword> [<rule category> | <rule category> . <rule id> | <rule category > - <rule severity> | ALL ] <suppression comment>

Examples

AUTOSAR-A27_0_4 violations (AUTOSAR-A27_0_4-a, -b, ...)"
  int j = 0;        // parasoft-suppress AUTOSAR "suppress all AUTOSAR violations"
  return i + (++j); // parasoft-suppress ALL "suppress all violations"
}

Block Suppression

Block suppression allows for suppressing violations in a block of code. The suppression begin/end comments must be specified before/after the block of code where the violations occur, using the following syntax:

Code Block
Code Block
// parasoft-begin-suppress CODSTA "begin suppress all rules in category CODSTA"
.....
// parasoft-end-suppress CODSTA "end suppress all rules in category CODSTA"

// parasoft-begin-suppress CODSTA.NEA "begin suppress rule CODSTA.NEA"
.....
// parasoft-end-suppress CODSTA.NEA "end suppress rule CODSTA.NEA"
 
// parasoft-begin-suppress CODSTA-1<rule-id>|<rule-category>|ALL "begin suppress all rules in category CODSTA with severity level 1<suppression comment>"
... code block ...
// parasoft-end-suppress CODSTA-1  <rule-id>|<rule-category>|ALL "end suppress all rules in category CODSTA with severity level 1"

//<suppression comment>"

Examples:

Code Block
int proc2(int i)
{
  // parasoft-begin-suppress ALL "begin suppress all rulesviolations"
.....
// parasoft-end-suppress ALLchar "end* suppressm all= rules"msg"
;
// parasoft-begin-suppress CODSTAint FORMAT.MCH "begin suppress all rules in category CODSTA and rule FORMAT.MCH"
.....
j = 0;
  return i + (++j);
  // parasoft-end-suppress CODSTA  FORMAT.MCHALL "end suppress all rules in category CODSTA and rule FORMAT.MCH"

violations"
}

int proc3(int i)
{
  // parasoft-begin-suppress CODSTAAUTOSAR "begin suppress all rules in category CODSTA"
.....
// parasoft-end-suppress CODSTA-1 "end suppress all rules in category CODSTA with severity level 1; however rules with severity level 2-5 in category CODSTA are still suppressed."
.....
AUTOSAR violations"
  char * m = "msg";
  int j = 0;
  // parasoft-end-suppress   CODSTAAUTOSAR "end suppress all rules in category CODSTA"
  AUTOSAR violations"
  return i + (++j);
}

// parasoft-begin-suppress ALL "begin suppress all rules"
.....
// parasoft-end-suppress CODSTA FORMAT-1 "end suppress all rules in category CODSTA and all rules in category FORMAT with severity level 1; however, others rules in CODSTA and FORMAT-1 are still suppressed."
..... AUTOSAR-A8_5_2-a AUTOSAR-A0_1_1-a "suppress all AUTOSAR-A8_5_2-a and AUTOSAR-A0_1_1-a violations"
int proc4(int i)
{
  char * m = "msg";
  int j = 0;
  return i + (++j);
}
// parasoft-end-suppress ALL "end suppress all rules"
 
//parasoft-begin-suppress ALL "begin suppress all rules, since no end suppression comment, all rules will be suppressed starting from this line AUTOSAR-A8_5_2-a AUTOSAR-A0_1_1-a "suppress all AUTOSAR-A8_5_2-a and AUTOSAR-A0_1_1-a violations"

Anchor
In-file Suppressions Format
In-file Suppressions Format
Defining Suppressions in Suppression Files

...

Use the following format to add suppression entries to parasoft.suppress files:

Code Block
suppression-begin
file: Account.cpp                 (required)
line: 12                          (optional)
rule-id: CODSTA-123               (optional)
message: Exact violation message  (optional)
reason: Approved                  (optional)
author: devel                     (optional)
date: 2020-09-21                  (optional)
suppression-end

Example:

At a minimum, you must specify the source file where the problem was detected. This will suppress all findings reported for the specified file. In the following example, all findings detected in the Account file will be suppressed:

Code Block
suppression-begin
file: Account.cpp
reason: false positive
suppression-end

Other attributes are optional and help you fine-tune the suppression. In the following example, all findings that the PB.TYPO.TLS rule detected in the Account file are suppressed, regardless on which code line they occur:

Code Block
suppression-begin
file: Account.cpp
rule-id: PB.TYPO.TLS
suppression-end

Notes on Attributes

  • It is a good practice to specify the reason for suppression.
  • The line attribute should be used with caution as it may invalidate the suppression if the code is moved to another line when the source file is modified.

...

Code Block
cpptest.result.line.suppressions.enabled=true
cpptest.result.line.suppressions.pattern=.*Q_.*

Scroll Pagebreak