cppcheck-htmlreport: Handle errors with multiple locations (#1488)

This commit is contained in:
Malcolm Parsons 2018-11-23 10:58:19 +00:00 committed by Daniel Marjamäki
parent 358f0c473d
commit 344424b759
1 changed files with 47 additions and 44 deletions

View File

@ -330,6 +330,10 @@ class CppCheckHandler(XmlContentHandler):
self.errors.append({ self.errors.append({
'file': attributes.get('file', ''), 'file': attributes.get('file', ''),
'line': int(attributes.get('line', 0)), 'line': int(attributes.get('line', 0)),
'locations': [{
'file': attributes.get('file', ''),
'line': int(attributes.get('line', 0)),
}],
'id': attributes['id'], 'id': attributes['id'],
'severity': attributes['severity'], 'severity': attributes['severity'],
'msg': attributes['msg'] 'msg': attributes['msg']
@ -339,51 +343,36 @@ class CppCheckHandler(XmlContentHandler):
if name == 'cppcheck': if name == 'cppcheck':
self.versionCppcheck = attributes['version'] self.versionCppcheck = attributes['version']
if name == 'error': if name == 'error':
# is there a better solution than this? error = {
if ('inconclusive' in attributes and 'cwe' in attributes): 'locations': [],
self.errors.append({ 'file': '',
'file': '', 'line': 0,
'line': 0, 'id': attributes['id'],
'id': attributes['id'], 'severity': attributes['severity'],
'severity': attributes['severity'], 'msg': attributes['msg'],
'msg': attributes['msg'], 'verbose': attributes.get('verbose')
'verbose': attributes.get('verbose'), }
'inconclusive': attributes['inconclusive'],
'cwe': attributes['cwe'] if 'inconclusive' in attributes:
}) error['inconclusive'] = attributes['inconclusive']
elif 'inconclusive' in attributes: if 'cwe' in attributes:
self.errors.append({ error['cwe'] = attributes['cwe']
'file': '',
'line': 0, self.errors.append(error)
'id': attributes['id'],
'severity': attributes['severity'],
'msg': attributes['msg'],
'verbose': attributes.get('verbose'),
'inconclusive': attributes['inconclusive']
})
elif 'cwe' in attributes:
self.errors.append({
'file': '',
'line': 0,
'id': attributes['id'],
'severity': attributes['severity'],
'msg': attributes['msg'],
'verbose': attributes.get('verbose'),
'cwe': attributes['cwe']
})
else:
self.errors.append({
'file': '',
'line': 0,
'id': attributes['id'],
'severity': attributes['severity'],
'msg': attributes['msg'],
'verbose': attributes.get('verbose')
})
elif name == 'location': elif name == 'location':
assert self.errors assert self.errors
self.errors[-1]['file'] = attributes['file'] error = self.errors[-1]
self.errors[-1]['line'] = int(attributes['line']) locations = error['locations']
file = attributes['file']
line = int(attributes['line'])
if not locations:
error['file'] = file
error['line'] = line
locations.append({
'file': file,
'line': line,
'info': attributes.get('info')
})
if __name__ == '__main__': if __name__ == '__main__':
# Configure all the options this little utility is using. # Configure all the options this little utility is using.
@ -464,7 +453,21 @@ if __name__ == '__main__':
decode_errors = [] decode_errors = []
for filename, data in sorted(files.items()): for filename, data in sorted(files.items()):
htmlfile = data['htmlfile'] htmlfile = data['htmlfile']
errors = data['errors'] errors = []
for error in data['errors']:
for location in error['locations']:
if filename == location['file']:
newError = dict(error)
del newError['locations']
newError['line'] = location['line']
if location.get('info'):
newError['msg'] = location['info']
newError['severity'] = 'information'
del newError['verbose']
errors.append(newError)
lines = [] lines = []
for error in errors: for error in errors: