diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport
index 57164b749..2c8c32159 100755
--- a/htmlreport/cppcheck-htmlreport
+++ b/htmlreport/cppcheck-htmlreport
@@ -275,15 +275,17 @@ class AnnotateCodeFormatter(HtmlFormatter):
if error['line'] == line_no:
try:
if error['inconclusive'] == 'true':
- if error.get('verbose') and (error['verbose'] != error['msg']): # only print verbose msg if it really differs from actual message
+ # only print verbose msg if it really differs
+ # from actual message
+ if error.get('verbose') and (error['verbose'] != error['msg']):
index = t.rfind('\n')
- t = t[:index] + HTML_EXPANDABLE_INCONCLUSIVE % (error['msg'], html_escape(error['verbose'].replace("\\012", '\n'))) + t[index+1:]
+ t = t[:index] + HTML_EXPANDABLE_INCONCLUSIVE % (error['msg'], html_escape(error['verbose'].replace("\\012", '\n'))) + t[index + 1:]
else:
t = t.replace('\n', HTML_INCONCLUSIVE % error['msg'])
except KeyError:
if error.get('verbose') and (error['verbose'] != error['msg']):
index = t.rfind('\n')
- t = t[:index] + HTML_EXPANDABLE_ERROR % (error['msg'], html_escape(error['verbose'].replace("\\012", '\n'))) + t[index+1:]
+ t = t[:index] + HTML_EXPANDABLE_ERROR % (error['msg'], html_escape(error['verbose'].replace("\\012", '\n'))) + t[index + 1:]
else:
t = t.replace('\n', HTML_ERROR % error['msg'])
@@ -521,7 +523,7 @@ if __name__ == '__main__':
except IndexError:
cnt_min = 0
- for occurrences in reversed(range(cnt_min, cnt_max+1)):
+ for occurrences in reversed(range(cnt_min, cnt_max + 1)):
for _id in [k for k, v in sorted(Counter(stats).items()) if v == occurrences]:
stat_html.append(" " + str(dict(Counter(stats).most_common())[_id]) + " " + str(_id) + "
\n")
@@ -584,14 +586,13 @@ if __name__ == '__main__':
'w') as css_file:
css_file.write(STYLE_FILE)
-
print("Creating stats.html (statistics)\n")
- stats_countlist={}
+ stats_countlist = {}
for filename, data in sorted(files.items()):
if (filename == ''):
continue
- stats_tmplist=[]
+ stats_tmplist = []
for error in sorted(data['errors'], key=lambda k: k['line']):
stats_tmplist.append(error['severity'])
@@ -607,37 +608,39 @@ if __name__ == '__main__':
for sev in SEVERITIES:
_sum = 0
- stats_templist={}
+ stats_templist = {}
- try: # if the we have an style warning but we are checking for portability, we have to skip it to prevent KeyError
+ # if the we have an style warning but we are checking for
+ # portability, we have to skip it to prevent KeyError
+ try:
for filename in stats_countlist:
- try: # also bail out if we have a file with no sev-results
+ try: # also bail out if we have a file with no sev-results
_sum += stats_countlist[filename][sev]
- stats_templist[filename] = (int)(stats_countlist[filename][sev]) # file : amount,
+ stats_templist[filename] = (int)(stats_countlist[filename][sev]) # file : amount,
except KeyError:
continue
- if (_sum == 0): # don't print "0 style" etc, if no style warnings were found
+ # don't print "0 style" etc, if no style warnings were found
+ if (_sum == 0):
break
except KeyError:
continue
stats_file.write("
Top 10 files for " + sev + " severity, total findings: " + str(_sum) + "\n") - # sort, so that the file with the most severities per type is first - stats_list_sorted = sorted(stats_templist.items(), key=operator.itemgetter(1,0), reverse=True) + stats_list_sorted = sorted(stats_templist.items(), key=operator.itemgetter(1, 0), reverse=True) it = 0 LENGTH = 0 - for i in stats_list_sorted: # printing loop - # for aesthetics: if it's the first iteration of the loop, get the max length of the number string + for i in stats_list_sorted: # printing loop + # for aesthetics: if it's the first iteration of the loop, get + # the max length of the number string if (it == 0): - LENGTH = len(str(i[1])) # <- length of longest number, now get the difference and try to make other numbers align to it + LENGTH = len(str(i[1])) # <- length of longest number, now get the difference and try to make other numbers align to it - stats_file.write(" "*3 + str(i[1]) + " "*(1 + LENGTH - len(str(i[1]))) + " " + i[0] + "\n") + stats_file.write(" " * 3 + str(i[1]) + " " * (1 + LENGTH - len(str(i[1]))) + " " + i[0] + "\n") it += 1 - if (it == 10): # print only the top 10 + if (it == 10): # print only the top 10 break stats_file.write("
\n") print("\nOpen '" + options.report_dir + "/index.html' to see the results.") - diff --git a/tools/ci.py b/tools/ci.py index 677f3d583..52fb067fe 100644 --- a/tools/ci.py +++ b/tools/ci.py @@ -32,6 +32,8 @@ def upload(file_to_upload, destination): pass # git push + + def gitpush(): try: password = sys.argv[1] diff --git a/tools/cppcheckdata.py b/tools/cppcheckdata.py index e382d6122..7f7f9a612 100644 --- a/tools/cppcheckdata.py +++ b/tools/cppcheckdata.py @@ -3,51 +3,52 @@ from lxml import etree + class Token: - Id = None - str = None - next = None - previous = None - scopeId = None - scope = None - isName = None - isNumber = None - isInt = None - isFloat = None - isString = None - strlen = None - isChar = None - isOp = None + Id = None + str = None + next = None + previous = None + scopeId = None + scope = None + isName = None + isNumber = None + isInt = None + isFloat = None + isString = None + strlen = None + isChar = None + isOp = None isArithmeticalOp = None - isAssignmentOp = None - isComparisonOp = None - isLogicalOp = None - linkId = None - link = None - varId = None - variableId = None - variable = None - functionId = None - function = None - valuesId = None - values = None - astParentId = None - astParent = None - astOperand1Id = None - astOperand1 = None - astOperand2Id = None - astOperand2 = None - file = None - linenr = None + isAssignmentOp = None + isComparisonOp = None + isLogicalOp = None + linkId = None + link = None + varId = None + variableId = None + variable = None + functionId = None + function = None + valuesId = None + values = None + astParentId = None + astParent = None + astOperand1Id = None + astOperand1 = None + astOperand2Id = None + astOperand2 = None + file = None + linenr = None def __init__(self, element): - self.Id = element.get('id') - self.str = element.get('str') - self.next = None - self.previous = None - self.scopeId = element.get('scope') - self.scope = None - type = element.get('type') + self.Id = element.get('id') + self.str = element.get('str') + self.next = None + self.previous = None + self.scopeId = element.get('scope') + self.scope = None + type = element.get('type') if type == 'name': self.isName = True elif type == 'number': @@ -71,37 +72,37 @@ class Token: self.isComparisonOp = True elif element.get('isLogicalOp'): self.isLogicalOp = True - self.linkId = element.get('link') - self.link = None - self.varId = element.get('varId') - self.variableId = element.get('variable') - self.variable = None - self.functionId = element.get('function') - self.function = None - self.valuesId = element.get('values') - self.values = None - self.astParentId = element.get('astParent') - self.astParent = None + self.linkId = element.get('link') + self.link = None + self.varId = element.get('varId') + self.variableId = element.get('variable') + self.variable = None + self.functionId = element.get('function') + self.function = None + self.valuesId = element.get('values') + self.values = None + self.astParentId = element.get('astParent') + self.astParent = None self.astOperand1Id = element.get('astOperand1') - self.astOperand1 = None + self.astOperand1 = None self.astOperand2Id = element.get('astOperand2') - self.astOperand2 = None - self.file = element.get('file') - self.linenr = element.get('linenr') + self.astOperand2 = None + self.file = element.get('file') + self.linenr = element.get('linenr') def setId(self, IdMap): - self.scope = IdMap[self.scopeId] - self.link = IdMap[self.linkId] - self.variable = IdMap[self.variableId] - self.function = IdMap[self.functionId] - self.values = IdMap[self.valuesId] - self.astParent = IdMap[self.astParentId] + self.scope = IdMap[self.scopeId] + self.link = IdMap[self.linkId] + self.variable = IdMap[self.variableId] + self.function = IdMap[self.functionId] + self.values = IdMap[self.valuesId] + self.astParent = IdMap[self.astParentId] self.astOperand1 = IdMap[self.astOperand1Id] self.astOperand2 = IdMap[self.astOperand2Id] # Get value if it exists # Returns None if it doesn't exist - def getValue(self,v): + def getValue(self, v): if not self.values: return None for value in self.values: @@ -109,110 +110,120 @@ class Token: return value return None -class Scope: - Id = None - classStartId = None - classStart = None - classEndId = None - classEnd = None - className = None - type = None - def __init__(self,element): - self.Id = element.get('id') - self.className = element.get('className') +class Scope: + Id = None + classStartId = None + classStart = None + classEndId = None + classEnd = None + className = None + type = None + + def __init__(self, element): + self.Id = element.get('id') + self.className = element.get('className') self.classStartId = element.get('classStart') - self.classStart = None - self.classEndId = element.get('classEnd') - self.classEnd = None - self.nestedInId = element.get('nestedId') - self.nestedIn = None - self.type = element.get('type') + self.classStart = None + self.classEndId = element.get('classEnd') + self.classEnd = None + self.nestedInId = element.get('nestedId') + self.nestedIn = None + self.type = element.get('type') def setId(self, IdMap): self.classStart = IdMap[self.classStartId] self.classEnd = IdMap[self.classEndId] self.nestedIn = IdMap[self.nestedInId] + class Function: - Id = None - argument = None + Id = None + argument = None argumentId = None - def __init__(self,element): - self.Id = element.get('id') - self.argument = {} + + def __init__(self, element): + self.Id = element.get('id') + self.argument = {} self.argumentId = {} for arg in element: self.argumentId[arg.get('nr')] = arg.get('id') + def setId(self, IdMap): for argnr, argid in self.argumentId.items(): self.argument[argnr] = IdMap[argid] + class Variable: - Id = None - nameTokenId = None - nameToken = None + Id = None + nameTokenId = None + nameToken = None typeStartTokenId = None - typeStartToken = None - typeEndTokenId = None - typeEndToken = None - isArgument = None - isArray = None - isClass = None - isLocal = None - isPointer = None - isReference = None - isStatic = None + typeStartToken = None + typeEndTokenId = None + typeEndToken = None + isArgument = None + isArray = None + isClass = None + isLocal = None + isPointer = None + isReference = None + isStatic = None def __init__(self, element): - self.Id = element.get('id') - self.nameTokenId = element.get('nameToken') - self.nameToken = None + self.Id = element.get('id') + self.nameTokenId = element.get('nameToken') + self.nameToken = None self.typeStartTokenId = element.get('typeStartToken') - self.typeStartToken = None - self.typeEndTokenId = element.get('typeEndToken') - self.typeEndToken = None - self.isArgument = element.get('isArgument') - self.isArray = element.get('isArray') - self.isClass = element.get('isClass') - self.isLocal = element.get('isLocal') - self.isPointer = element.get('isPointer') - self.isReference = element.get('isReference') - self.isStatic = element.get('isStatic') + self.typeStartToken = None + self.typeEndTokenId = element.get('typeEndToken') + self.typeEndToken = None + self.isArgument = element.get('isArgument') + self.isArray = element.get('isArray') + self.isClass = element.get('isClass') + self.isLocal = element.get('isLocal') + self.isPointer = element.get('isPointer') + self.isReference = element.get('isReference') + self.isStatic = element.get('isStatic') def setId(self, IdMap): self.nameToken = IdMap[self.nameTokenId] self.typeStartToken = IdMap[self.typeStartTokenId] self.typeEndToken = IdMap[self.typeEndTokenId] + class ValueFlow: + class Value: intvalue = None condition = None + def __init__(self, element): self.intvalue = int(element.get('intvalue')) self.condition = element.get('condition-line') if self.condition: self.condition = int(self.condition) - Id = None + Id = None values = None + def __init__(self, element): - self.Id = element.get('id') + self.Id = element.get('id') self.values = [] for value in element: self.values.append(ValueFlow.Value(value)) + class CppcheckData: tokenlist = [] - scopes = [] + scopes = [] functions = [] variables = [] valueflow = [] def __init__(self, filename): self.tokenlist = [] - self.scopes = [] + self.scopes = [] self.variables = [] self.valueflow = [] @@ -245,7 +256,7 @@ class CppcheckData: IdMap = {} IdMap[None] = None - IdMap['0'] = None + IdMap['0'] = None for token in self.tokenlist: IdMap[token.Id] = token for scope in self.scopes: @@ -266,10 +277,13 @@ class CppcheckData: for variable in self.variables: variable.setId(IdMap) + def parsedump(filename): return CppcheckData(filename) # Check if type of ast node is float/double + + def astIsFloat(token): if not token: return False @@ -283,7 +297,7 @@ def astIsFloat(token): # float literal? if token.str[0].isdigit(): for c in token.str: - if c=='f' or c=='.' or c=='E': + if c == 'f' or c == '.' or c == 'E': return True return False typeToken = token.variable.typeStartToken diff --git a/tools/daca2-download.py b/tools/daca2-download.py index 740f84608..3802c3f38 100644 --- a/tools/daca2-download.py +++ b/tools/daca2-download.py @@ -125,6 +125,7 @@ def removeLargeFiles(path): elif g[-2:] != '.C' and g[-2:] != '.c' and g[-4:] != '.cc' and g[-4:] != '.cpp' and g[-4:] != '.cxx' and g[-2:] != '.h' and g[-2:] != '.H' and g[-4:] != '.c++' and g[-4:] != '.hpp' and g[-4:] != '.tpp' and g[-4:] != '.t++': os.remove(g) + def downloadpackage(filepath, outpath): # remove all files/folders removeAll() diff --git a/tools/daca2.py b/tools/daca2.py index 74612f019..de3f760c6 100644 --- a/tools/daca2.py +++ b/tools/daca2.py @@ -146,7 +146,7 @@ def scanarchive(filepath, jobs): # # List of skipped packages - which trigger known yet unresolved problems with cppcheck. -# The issues on trac (http://trac.cppcheck.net) are given for reference +# The issues on trac (http://trac.cppcheck.net) are given for reference # boost #3654 (?) # flite #5975 # insight#5184 diff --git a/tools/parse-glibc.py b/tools/parse-glibc.py index 9e976e92a..6c8e5d1b5 100644 --- a/tools/parse-glibc.py +++ b/tools/parse-glibc.py @@ -2,123 +2,123 @@ import glob import os -def checknonnull(cfg, functionName, nonnull): - pos1 = cfg.find('