parent
bdc024bd7c
commit
c090ed2fc9
|
@ -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) + "<br/>\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
|
||||
_sum += stats_countlist[filename][sev]
|
||||
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("<p>Top 10 files for " + sev + " severity, total findings: " + str(_sum) + "</br>\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 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
|
||||
|
||||
stats_file.write(" "*3 + str(i[1]) + " "*(1 + LENGTH - len(str(i[1]))) + "<a href=\"" + files[i[0]]['htmlfile'] + "\"> " + i[0] + "</a></br>\n")
|
||||
stats_file.write(" " * 3 + str(i[1]) + " " * (1 + LENGTH - len(str(i[1]))) + "<a href=\"" + files[i[0]]['htmlfile'] + "\"> " + i[0] + "</a></br>\n")
|
||||
it += 1
|
||||
if (it == 10): # print only the top 10
|
||||
break
|
||||
stats_file.write("</p>\n")
|
||||
|
||||
print("\nOpen '" + options.report_dir + "/index.html' to see the results.")
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ def upload(file_to_upload, destination):
|
|||
pass
|
||||
|
||||
# git push
|
||||
|
||||
|
||||
def gitpush():
|
||||
try:
|
||||
password = sys.argv[1]
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
from lxml import etree
|
||||
|
||||
|
||||
class Token:
|
||||
Id = None
|
||||
str = None
|
||||
|
@ -101,7 +102,7 @@ class Token:
|
|||
|
||||
# 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,6 +110,7 @@ class Token:
|
|||
return value
|
||||
return None
|
||||
|
||||
|
||||
class Scope:
|
||||
Id = None
|
||||
classStartId = None
|
||||
|
@ -118,7 +120,7 @@ class Scope:
|
|||
className = None
|
||||
type = None
|
||||
|
||||
def __init__(self,element):
|
||||
def __init__(self, element):
|
||||
self.Id = element.get('id')
|
||||
self.className = element.get('className')
|
||||
self.classStartId = element.get('classStart')
|
||||
|
@ -134,20 +136,24 @@ class Scope:
|
|||
self.classEnd = IdMap[self.classEndId]
|
||||
self.nestedIn = IdMap[self.nestedInId]
|
||||
|
||||
|
||||
class Function:
|
||||
Id = None
|
||||
argument = None
|
||||
argumentId = None
|
||||
def __init__(self,element):
|
||||
|
||||
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
|
||||
|
@ -185,10 +191,13 @@ class Variable:
|
|||
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')
|
||||
|
@ -197,12 +206,14 @@ class ValueFlow:
|
|||
|
||||
Id = None
|
||||
values = None
|
||||
|
||||
def __init__(self, element):
|
||||
self.Id = element.get('id')
|
||||
self.values = []
|
||||
for value in element:
|
||||
self.values.append(ValueFlow.Value(value))
|
||||
|
||||
|
||||
class CppcheckData:
|
||||
tokenlist = []
|
||||
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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import glob
|
||||
import os
|
||||
|
||||
|
||||
def checknonnull(cfg, functionName, nonnull):
|
||||
pos1 = cfg.find('<function name="' + functionName + '">')
|
||||
if pos1 < 0:
|
||||
|
@ -12,7 +13,7 @@ def checknonnull(cfg, functionName, nonnull):
|
|||
functionCfg = cfg[pos1:pos2]
|
||||
s = None
|
||||
for argnr in range(10):
|
||||
argpos1 = functionCfg.find('<arg nr="'+str(argnr)+'">')
|
||||
argpos1 = functionCfg.find('<arg nr="' + str(argnr) + '">')
|
||||
if argpos1 < 0:
|
||||
continue
|
||||
argpos2 = functionCfg.find('</arg>', argpos1)
|
||||
|
@ -30,9 +31,8 @@ def checknonnull(cfg, functionName, nonnull):
|
|||
print(functionName + '\tglibc:' + nonnull + '\tcfg:' + s)
|
||||
|
||||
|
||||
|
||||
def parseheader(cppcheckpath, filename):
|
||||
f = open(filename,'rt')
|
||||
f = open(filename, 'rt')
|
||||
data = f.read()
|
||||
f.close()
|
||||
|
||||
|
@ -46,14 +46,14 @@ def parseheader(cppcheckpath, filename):
|
|||
|
||||
while data.find('/*') >= 0:
|
||||
pos1 = data.find('/*')
|
||||
pos2 = data.find('*/', pos1+2)
|
||||
data = data[:pos1] + data[pos2+2:]
|
||||
pos2 = data.find('*/', pos1 + 2)
|
||||
data = data[:pos1] + data[pos2 + 2:]
|
||||
|
||||
data = data.replace('\\\n', '')
|
||||
|
||||
while data.find('\n#') >= 0:
|
||||
pos1 = data.find('\n#')
|
||||
pos2 = data.find('\n', pos1+1)
|
||||
pos2 = data.find('\n', pos1 + 1)
|
||||
data = data[:pos1] + data[pos2:]
|
||||
|
||||
while data.find('\n__BEGIN') >= 0:
|
||||
|
@ -96,7 +96,7 @@ def parseheader(cppcheckpath, filename):
|
|||
if not line[functionNameStart].isalpha():
|
||||
continue
|
||||
|
||||
functionName = line[functionNameStart:functionNameEnd+1]
|
||||
functionName = line[functionNameStart:functionNameEnd + 1]
|
||||
|
||||
nonnull = None
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ numberOfFalseNegatives = 0
|
|||
for result in results.split('\n'):
|
||||
result = result.strip()
|
||||
|
||||
res = re.match('\\[('+project+'.+):([0-9]+)\\]:\s+[(][a-z]+[)] (.+)', result)
|
||||
res = re.match('\\[(' + project + '.+):([0-9]+)\\]:\s+[(][a-z]+[)] (.+)', result)
|
||||
if res is None:
|
||||
continue
|
||||
|
||||
|
@ -55,15 +55,15 @@ for result in results.split('\n'):
|
|||
href = None
|
||||
|
||||
html = ' <tr>'
|
||||
html += '<td class='+css+'>'+filename+'</td>'
|
||||
html += '<td class='+css+'>'+linenr+'</td>'
|
||||
html += '<td class='+css+'>'+message+'</td>'
|
||||
html += '<td class=' + css + '>' + filename + '</td>'
|
||||
html += '<td class=' + css + '>' + linenr + '</td>'
|
||||
html += '<td class=' + css + '>' + message + '</td>'
|
||||
if project == 'linux-3.11':
|
||||
href = 'http://github.com/torvalds/linux/blob/v3.11' + filename[filename.find('/'):] + '#L' + linenr
|
||||
if href:
|
||||
html += '<td class='+css+'><a href="' + href + '">' + classification + '</a></td>'
|
||||
html += '<td class=' + css + '><a href="' + href + '">' + classification + '</a></td>'
|
||||
else:
|
||||
html += '<td class='+css+'>' + classification + '</td>'
|
||||
html += '<td class=' + css + '>' + classification + '</td>'
|
||||
html += '</tr>\n'
|
||||
|
||||
out[css] += html
|
||||
|
@ -74,7 +74,7 @@ for line in f.readlines():
|
|||
if line.find('] -> [') > 0 or line.find('(error)') < 0:
|
||||
continue
|
||||
|
||||
res = re.match('\\[('+project+'.+):([0-9]+)\\]:\s+[(][a-z]+[)] (.+)', line)
|
||||
res = re.match('\\[(' + project + '.+):([0-9]+)\\]:\s+[(][a-z]+[)] (.+)', line)
|
||||
if res is None:
|
||||
continue
|
||||
|
||||
|
@ -90,10 +90,10 @@ for line in f.readlines():
|
|||
css = 'fn'
|
||||
|
||||
html = ' <tr>'
|
||||
html += '<td class='+css+'>'+filename+'</td>'
|
||||
html += '<td class='+css+'>'+linenr+'</td>'
|
||||
html += '<td class='+css+'>'+message+'</td>'
|
||||
html += '<td class='+css+'>'+classification+'</td>'
|
||||
html += '<td class=' + css + '>' + filename + '</td>'
|
||||
html += '<td class=' + css + '>' + linenr + '</td>'
|
||||
html += '<td class=' + css + '>' + message + '</td>'
|
||||
html += '<td class=' + css + '>' + classification + '</td>'
|
||||
html += '</tr>\n'
|
||||
|
||||
out[css] += html
|
||||
|
|
Loading…
Reference in New Issue