From c1c4ffd700849d37b9e661d08668f091a40d1356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 30 Aug 2011 20:30:52 +0200 Subject: [PATCH] Fixed #3057 (cppcheck-htmlreport fails since 1.50) --- htmlreport/cppcheck-htmlreport | 43 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 1afa1ec0e..3a0f55e39 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -181,16 +181,26 @@ class CppCheckHandler(XmlContentHandler): if name != "error": return - 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 attributes["id"] == "missingInclude": + self.errors.append( + { + "file" : "", + "line" : 0, + "id" : attributes["id"], + "severity" : attributes["severity"], + "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__': # Configure all the options this little utility is using. @@ -257,6 +267,9 @@ if __name__ == '__main__': for error in errors: lines.append(error["line"]) + if filename == "": + continue + source_file = os.path.join(source_dir, filename) if not os.path.isfile(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(): stream.write("%s" % (data["htmlfile"], filename)) for error in data["errors"]: - stream.write("%d%s%s%s" % - (data["htmlfile"], error["line"], error["line"], error["id"], - error["severity"], error["msg"])) + if error["id"] == "missingInclude": + stream.write("%s%s%s" % + (error["id"], error["severity"], error["msg"])) + else: + stream.write("%d%s%s%s" % + (data["htmlfile"], error["line"], error["line"], error["id"], + error["severity"], error["msg"])) stream.write("") stream.write(HTML_FOOTER) stream.close()