...
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 |
---|
icon | false |
---|
title | Suppressing 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
...
Code Block |
---|
// parasoft-suppress <rule-id>|<rule-category>|ALL "<suppression comment>" |
Examples:
Code Block |
---|
int proc1(bool a, bool b, int i)
{
if (a | b) // parasoft-suppress CERT_C "suppress |
...
all rules in category CERT_C"
if (b = a)// parasoft-suppress CERT_C-EXP45 "suppress rule CERT_C-EXP45"
{
std::string emptyString1 = ""; // parasoft-suppress |
...
...
rules in category Joint Strike Fighter with severity level 3"
}
else
{
std::string emptyString2 = ""; // parasoft-suppress |
...
CERT_C-DCL00 JSF-043 JSF-051 "suppress multiple rules"
|
...
...
...
...
...
; // parasoft-suppress ALL "suppress all |
...
Anchor |
---|
| block_suppression |
---|
| block_suppression |
---|
|
Block Suppression
...
Code Block |
---|
// parasoft-begin-suppress <rule-id>|<rule-category>|ALL "<suppression comment>"
... code block ...
// parasoft-end-suppress <rule-id>|<rule-category>|ALL "<suppression comment>" |
Examples:
Code Block |
---|
int proc2(bool a, bool b, int i)
{
// parasoft-begin-suppress |
...
CERT_C "begin suppress all |
...
rules in category CERT_C"
if (a | b)
if(b = a)
// parasoft-end-suppress CERT_C "end suppress all rules in category CERT_C"
{
std::string emptyString1 = "";
}
return i++;
}
int proc3(bool a, bool b, int i)
{
if (a | b)
// parasoft-begin-suppress CERT_C-EXP45 "begin suppress rule CERT_C-EXP45"
if(b = a)
// parasoft-end-suppress CERT_C-EXP45 "end suppress |
...
...
CERT_C-EXP45"
{
std::string emptyString1 = "";
}
return i++;
}
int proc4(bool a, bool b, int i)
{
// parasoft-begin-suppress |
...
JSF-3 "begin suppress all |
...
rules in category Joint Strike Fighter with severity level 3"
if (a | b)
if(b = a)
{
std::string emptyString1 = " |
...
...
...
...
...
i++;
// parasoft-end-suppress |
...
...
rules in category Joint Strike Fighter with severity level 3"
}
// parasoft-begin-suppress ALL |
...
"begin suppress all rules"
int proc5(bool a, bool b, int i)
{
if (a | b)
if(b = a)
{
std::string emptyString1 = "";
}
return i++;
}
// parasoft-end-suppress ALL "end suppress all |
...
To suppress multiple rules in a file, include the following at the beginning/end of the file:
Code Block |
---|
// parasoft-begin-suppress CERT_C-DCL00 JSF-043 JSF-051 "begin suppress multiple rules"
.....
// parasoft-end-suppress CERT_C-DCL00 JSF-043 JSF-051 "end suppress multiple rules" |
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_.*<OPT> |