Skip to content

Commit 344424b

Browse files
pepsimandanmar
authored andcommitted
cppcheck-htmlreport: Handle errors with multiple locations (danmar#1488)
1 parent 358f0c4 commit 344424b

File tree

1 file changed

+47
-44
lines changed

1 file changed

+47
-44
lines changed

htmlreport/cppcheck-htmlreport

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ class CppCheckHandler(XmlContentHandler):
330330
self.errors.append({
331331
'file': attributes.get('file', ''),
332332
'line': int(attributes.get('line', 0)),
333+
'locations': [{
334+
'file': attributes.get('file', ''),
335+
'line': int(attributes.get('line', 0)),
336+
}],
333337
'id': attributes['id'],
334338
'severity': attributes['severity'],
335339
'msg': attributes['msg']
@@ -339,51 +343,36 @@ class CppCheckHandler(XmlContentHandler):
339343
if name == 'cppcheck':
340344
self.versionCppcheck = attributes['version']
341345
if name == 'error':
342-
# is there a better solution than this?
343-
if ('inconclusive' in attributes and 'cwe' in attributes):
344-
self.errors.append({
345-
'file': '',
346-
'line': 0,
347-
'id': attributes['id'],
348-
'severity': attributes['severity'],
349-
'msg': attributes['msg'],
350-
'verbose': attributes.get('verbose'),
351-
'inconclusive': attributes['inconclusive'],
352-
'cwe': attributes['cwe']
353-
})
354-
elif 'inconclusive' in attributes:
355-
self.errors.append({
356-
'file': '',
357-
'line': 0,
358-
'id': attributes['id'],
359-
'severity': attributes['severity'],
360-
'msg': attributes['msg'],
361-
'verbose': attributes.get('verbose'),
362-
'inconclusive': attributes['inconclusive']
363-
})
364-
elif 'cwe' in attributes:
365-
self.errors.append({
366-
'file': '',
367-
'line': 0,
368-
'id': attributes['id'],
369-
'severity': attributes['severity'],
370-
'msg': attributes['msg'],
371-
'verbose': attributes.get('verbose'),
372-
'cwe': attributes['cwe']
373-
})
374-
else:
375-
self.errors.append({
376-
'file': '',
377-
'line': 0,
378-
'id': attributes['id'],
379-
'severity': attributes['severity'],
380-
'msg': attributes['msg'],
381-
'verbose': attributes.get('verbose')
382-
})
346+
error = {
347+
'locations': [],
348+
'file': '',
349+
'line': 0,
350+
'id': attributes['id'],
351+
'severity': attributes['severity'],
352+
'msg': attributes['msg'],
353+
'verbose': attributes.get('verbose')
354+
}
355+
356+
if 'inconclusive' in attributes:
357+
error['inconclusive'] = attributes['inconclusive']
358+
if 'cwe' in attributes:
359+
error['cwe'] = attributes['cwe']
360+
361+
self.errors.append(error)
383362
elif name == 'location':
384363
assert self.errors
385-
self.errors[-1]['file'] = attributes['file']
386-
self.errors[-1]['line'] = int(attributes['line'])
364+
error = self.errors[-1]
365+
locations = error['locations']
366+
file = attributes['file']
367+
line = int(attributes['line'])
368+
if not locations:
369+
error['file'] = file
370+
error['line'] = line
371+
locations.append({
372+
'file': file,
373+
'line': line,
374+
'info': attributes.get('info')
375+
})
387376

388377
if __name__ == '__main__':
389378
# Configure all the options this little utility is using.
@@ -464,7 +453,21 @@ if __name__ == '__main__':
464453
decode_errors = []
465454
for filename, data in sorted(files.items()):
466455
htmlfile = data['htmlfile']
467-
errors = data['errors']
456+
errors = []
457+
458+
for error in data['errors']:
459+
for location in error['locations']:
460+
if filename == location['file']:
461+
newError = dict(error)
462+
463+
del newError['locations']
464+
newError['line'] = location['line']
465+
if location.get('info'):
466+
newError['msg'] = location['info']
467+
newError['severity'] = 'information'
468+
del newError['verbose']
469+
470+
errors.append(newError)
468471

469472
lines = []
470473
for error in errors:

0 commit comments

Comments
 (0)