diff --git a/htmlreport/check.sh b/htmlreport/check.sh index 3815480ef..e9bf6e314 100755 --- a/htmlreport/check.sh +++ b/htmlreport/check.sh @@ -25,3 +25,11 @@ echo "" ../cppcheck --errorlist --inconclusive --xml-version=2 > errorlist.xml xmllint --noout errorlist.xml ./cppcheck-htmlreport --file ./errorlist.xml --title "errorlist" --report-dir . + +../cppcheck ../samples/memleak/good.c ../samples/resourceLeak/good.c --xml-version=2 --enable=information --suppressions-list=test_suppressions.txt --xml 2> unmatchedSuppr.xml +xmllint --noout unmatchedSuppr.xml +./cppcheck-htmlreport --file ./unmatchedSuppr.xml --title "unmatched Suppressions" --report-dir=. +grep "unmatchedSuppression<.*>information<.*>Unmatched suppression: variableScope*<" index.html +grep ">unmatchedSuppressioninformation<.*>Unmatched suppression: uninitstring<" index.html +grep "notexisting" index.html +grep ">unmatchedSuppression<.*>information<.*>Unmatched suppression: \*<" index.html diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 9359a1d3e..c90d47373 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -433,8 +433,11 @@ if __name__ == '__main__': with io.open(source_filename, 'r', encoding=options.source_encoding) as input_file: content = input_file.read() except IOError: - sys.stderr.write("ERROR: Source file '%s' not found.\n" % - source_filename) + if (error['id'] == 'unmatchedSuppression'): + continue; # file not found, bail out + else: + sys.stderr.write("ERROR: Source file '%s' not found.\n" % + source_filename) continue except UnicodeDecodeError: sys.stderr.write("WARNING: Unicode decode error in '%s'.\n" % @@ -522,9 +525,15 @@ if __name__ == '__main__': output_file.write("\n %s" % (filename)) output_file.write("\n Could not generated due to UnicodeDecodeError") else: - output_file.write( - "\n %s" % - (data['htmlfile'], filename)) + if filename.endswith('*'): # assume unmatched suppression + output_file.write( + "\n %s" % + (filename)) + else: + output_file.write( + "\n %s" % + (data['htmlfile'], filename)) + for error in sorted(data['errors'], key=lambda k: k['line']): error_class = '' try: @@ -540,6 +549,11 @@ if __name__ == '__main__': output_file.write( '\n %s%s%s' % (error['id'], error['severity'], error['msg'])) + elif (error['id'] == 'unmatchedSuppression') and filename.endswith('*'): + output_file.write( + "\n %s%s%s" % + (error['id'], error['severity'], error_class, + error['msg'])) else: output_file.write( "\n %d%s%s%s" % diff --git a/htmlreport/test_suppressions.txt b/htmlreport/test_suppressions.txt new file mode 100644 index 000000000..ec3130c09 --- /dev/null +++ b/htmlreport/test_suppressions.txt @@ -0,0 +1,3 @@ +variableScope:../samples/memleak/good.c +*:../samples/resourceLeak/notexisting.c* +uninitstring:*