Skip to content

Commit

Permalink
Fix #12477 use strings as types
Browse files Browse the repository at this point in the history
  • Loading branch information
wienans committed Feb 28, 2024
1 parent 3442fc2 commit 238d8bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
21 changes: 14 additions & 7 deletions addons/cppcheckdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << " </suppressions>" << std::endl;
Expand Down

0 comments on commit 238d8bc

Please sign in to comment.