Skip to content

Commit

Permalink
Fix suppression file excludes and misra test with inline suppress
Browse files Browse the repository at this point in the history
  • Loading branch information
wienans committed Feb 28, 2024
1 parent 238d8bc commit 10828cb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
9 changes: 7 additions & 2 deletions addons/cppcheckdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ def isMatch(self, file, line, message, errorId):
and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*'))
and fnmatch(errorId, self.errorId)):
return True
# Global Suppression
# File Suppression
if ((self.fileName is None or fnmatch(file, self.fileName))
and (self.suppressionType != None and self.suppressionType == "file") # Verify use of file (global) suppression type
and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*'))
Expand All @@ -997,7 +997,12 @@ def isMatch(self, file, line, message, errorId):
and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*'))
and fnmatch(errorId, self.errorId)):
return True
return False
# Other Suppression (Globaly set via suppression file or cli command)
if ((self.fileName is None or fnmatch(file, self.fileName))
and (self.suppressionType is None)
and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*'))
and fnmatch(errorId, self.errorId)):
return True


class Configuration:
Expand Down
4 changes: 4 additions & 0 deletions addons/test/misra/misra-suppressions1-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// This needs to stay at line number 7 to make the test pass
// If it is changed update suppressions.txt with the new line number
// cppcheck-suppress-file misra-c2012-5.2
#include <stdio.h> //21.6

extern int misra_5_2_var_hides_var______31x;//8.4
Expand All @@ -13,6 +14,8 @@ static void misra_5_2_function_hides_var_31y(void) {}//5.2
static void foo(void)
{
int i;
// cppcheck-suppress-begin misra-c2012-16.4
// cppcheck-suppress misra-c2012-16.6
switch(misra_5_2_func1()) //16.4 16.6
{
case 1:
Expand All @@ -30,4 +33,5 @@ static void foo(void)
} while(misra_5_2_func2()); //17.3
}
}
// cppcheck-suppress-end misra-c2012-16.4
}
1 change: 1 addition & 0 deletions addons/test/misra/misra-suppressions2-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// ../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c && python ../misra.py misra-suppressions*-test.c.dump
// There should be no violations reported

// cppcheck-suppress-file misra-c2012-5.2
union misra_5_2_field_hides_field__63x { //19.2
int misra_5_2_field_hides_field__31x;
int misra_5_2_field_hides_field__31y;//5.2
Expand Down
3 changes: 0 additions & 3 deletions addons/test/misra/suppressions.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
misra-c2012-21.6:*/misra-suppressions1-test.c:7
misra-c2012-17.3
misra-c2012-5.2
misra-c2012-8.4:*/misra-suppressions1-test.c
misra-c2012-16.4:*/misra-suppressions1-test.c
misra-c2012-16.6:*/misra-suppressions1-test.c
misra-c2012-4.1:*/misra-suppressions2-test.c
misra-c2012-8.4:*/misra-suppressions2-test.c
misra-c2012-19.2:*/misra-suppressions2-test.c
2 changes: 1 addition & 1 deletion addons/test/misra_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_rules_suppression(checker, capsys):
for src in test_sources:
re_suppressed= r"\[%s\:[0-9]+\]" % src
dump_remove(src)
dump_create(src, "--suppressions-list=addons/test/misra/suppressions.txt")
dump_create(src, "--suppressions-list=addons/test/misra/suppressions.txt --inline-suppr")
checker.parseDump(src + ".dump")
captured = capsys.readouterr().err
found = re.search(re_suppressed, captured)
Expand Down

0 comments on commit 10828cb

Please sign in to comment.