Fixed #3057 (cppcheck-htmlreport fails since 1.50)

This commit is contained in:
Daniel Marjamäki 2011-08-30 20:30:52 +02:00
parent 0529654e37
commit c1c4ffd700
1 changed files with 30 additions and 13 deletions

View File

@ -181,16 +181,26 @@ class CppCheckHandler(XmlContentHandler):
if name != "error": if name != "error":
return return
if attributes["file"] == "": if attributes["id"] == "missingInclude":
sys.stderr.write("ERROR: cppcheck error reported without a file name.\n") self.errors.append(
self.errors.append( {
{ "file" : "",
"file" : attributes["file"], "line" : 0,
"line" : int(attributes["line"]), "id" : attributes["id"],
"id" : attributes["id"], "severity" : attributes["severity"],
"severity" : attributes["severity"], "msg" : attributes["msg"]
"msg" : attributes["msg"] })
}) else:
if attributes["file"] == "":
sys.stderr.write("ERROR: cppcheck error reported without a file name.\n")
self.errors.append(
{
"file" : attributes["file"],
"line" : int(attributes["line"]),
"id" : attributes["id"],
"severity" : attributes["severity"],
"msg" : attributes["msg"]
})
if __name__ == '__main__': if __name__ == '__main__':
# Configure all the options this little utility is using. # Configure all the options this little utility is using.
@ -257,6 +267,9 @@ if __name__ == '__main__':
for error in errors: for error in errors:
lines.append(error["line"]) lines.append(error["line"])
if filename == "":
continue
source_file = os.path.join(source_dir, filename) source_file = os.path.join(source_dir, filename)
if not os.path.isfile(source_file): if not os.path.isfile(source_file):
sys.stderr.write("ERROR: Source file '%s' not found.\n" % source_file) sys.stderr.write("ERROR: Source file '%s' not found.\n" % source_file)
@ -290,9 +303,13 @@ if __name__ == '__main__':
for filename, data in files.iteritems(): for filename, data in files.iteritems():
stream.write("<tr><td colspan='4'><a href=\"%s\">%s</a></td></tr>" % (data["htmlfile"], filename)) stream.write("<tr><td colspan='4'><a href=\"%s\">%s</a></td></tr>" % (data["htmlfile"], filename))
for error in data["errors"]: for error in data["errors"]:
stream.write("<tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td>%s</td></tr>" % if error["id"] == "missingInclude":
(data["htmlfile"], error["line"], error["line"], error["id"], stream.write("<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>" %
error["severity"], error["msg"])) (error["id"], error["severity"], error["msg"]))
else:
stream.write("<tr><td><a href='%s#line-%d'>%d</a></td><td>%s</td><td>%s</td><td>%s</td></tr>" %
(data["htmlfile"], error["line"], error["line"], error["id"],
error["severity"], error["msg"]))
stream.write("</table>") stream.write("</table>")
stream.write(HTML_FOOTER) stream.write(HTML_FOOTER)
stream.close() stream.close()