def parse(self): """ parse the output of splint. Format of splint output is: [<file>:<line> (in <context>)] <file>:<line>[,<column>]: message [hint] <file>:<line>,<column>: extra location information, if appropriate Typical output looks like this test.c: (in function main) test.c:6:11: Fresh storage f not released before return A memory leak has been detected. Storage allocated locally is not released before the last reference to it is lost. (Use -mustfreefresh to inhibit warning) test.c:5:23: Fresh storage f created test.c:5:8: Variable f declared but not used A variable is declared but never used. Use /*@unused@*/ in front of declaration to suppress message. (Use -varuse to inhibit warning) """ # err_begin = re.compile("^([^\s]*):(\d+):(\d+):(.*)$") err_begin = re.compile("^([\w\.\/]+):(\d+):(\d+):(.*)$") context = re.compile("^[\w\.\/]+:\s+\(in\s+function\s+\w+\s*\)$") for line in open(self.output): m = context.match(line) if m: # skipe the function context message continue m = err_begin.match(line) if m: f = m.group(1) l = m.group(2) c = m.group(3) te = m.group(4) id = 0 # splint does not give his own error id :( e = ToolError.splint_error(id, l, c, f, te) self.add_error(e) else: # we might want to store these extra messages displayed by # splint. Let's skip them for some time. continue return 0
def analyse(self): """ analyse source code using cppcheck """ xml = "/tmp/output.xml" args = " --xml " + self.file_name + " 2> " + xml log.log(3, "\nAnalysing cpp code using cppcheck\n") r, o = self.run_cpp_check(args) x = CppCheckXMLParser(xml) errors = x.parse() for en in errors: f = errors[en]["file"] l = errors[en]["line"] c = 0 # cppcheck does not report column number te = errors[en]["msg"] id = errors[en]["id"] e = ToolError.cppcheck_error(id, l, c, f, te) # get error object self.add_error(e) for e in self.errors: print e