diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index f1d7730e37d..9d53a2f6d99 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -948,7 +948,7 @@ class Suppression: symbolName The name of the symbol to match warnings for, can include wildcards lineBegin The first line to suppress warnings from lineEnd The last line to suppress warnings from - suppressionType The type of suppression which is applied (unique = 0, file = 1, block = 2, blockBegin = 3, blockEnd = 4, macro = 5) + suppressionType The type of suppression which is applied (unique = None (default), file, block, blockBegin, blockEnd, macro) """ errorId = None @@ -969,24 +969,31 @@ def __init__(self, element): self.suppressionType = element.get('type') def __repr__(self): - attrs = ['errorId' , "fileName", "lineNumber", "symbolName"] + attrs = ["errorId", "fileName", "lineNumber", "symbolName", "lineBegin", "lineEnd","suppressionType"] return "{}({})".format( "Suppression", ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs)) ) def isMatch(self, file, line, message, errorId): - # Global and Line Suppression + # Line Suppression if ((self.fileName is None or fnmatch(file, self.fileName)) - and (self.lineNumber is None or int(self.suppressionType) == 1 or int(line) == int(self.lineNumber)) + and (self.suppressionType == None) # Verify use of default suppression type (None = unique) + and (self.lineNumber != None and int(line) == int(self.lineNumber)) + and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*')) + and fnmatch(errorId, self.errorId)): + return True + # Global 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+'*')) and fnmatch(errorId, self.errorId)): return True # Block Suppression Mode if ((self.fileName is None or fnmatch(file, self.fileName)) - and (int(self.suppressionType) == 2) # Type for Block suppression - and (int(line) > int(self.lineBegin)) # Code Match is between the Block suppression - and (int(line) < int(self.lineEnd)) # Code Match is between the Block suppression + and (self.suppressionType != None and self.suppressionType == "block") # Type for Block suppression + and (self.lineBegin != None and int(line) > int(self.lineBegin)) # Code Match is between the Block suppression + and (self.lineEnd != None and int(line) < int(self.lineEnd)) # Code Match is between the Block suppression and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*')) and fnmatch(errorId, self.errorId)): return True diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 173cf145b70..69bbe95229f 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -459,7 +459,16 @@ void SuppressionList::dump(std::ostream & out) const out << " lineBegin=\"" << suppression.lineBegin << '"'; if (suppression.lineEnd != Suppression::NO_LINE) out << " lineEnd=\"" << suppression.lineEnd << '"'; - out << " type=\"" << (int) suppression.type << '"'; + if (suppression.type == SuppressionList::Type::file) + out << " type=\"file\""; + else if (suppression.type == SuppressionList::Type::block) + out << " type=\"block\""; + else if (suppression.type == SuppressionList::Type::blockBegin) + out << " type=\"blockBegin\""; + else if (suppression.type == SuppressionList::Type::blockEnd) + out << " type=\"blockEnd\""; + else if (suppression.type == SuppressionList::Type::macro) + out << " type=\"macro\""; out << " />" << std::endl; } out << " " << std::endl;