diff --git a/addons/cert.py b/addons/cert.py index 4d8517a2f..a1ecc8d6e 100755 --- a/addons/cert.py +++ b/addons/cert.py @@ -20,13 +20,9 @@ CLI = False def reportError(token, severity, msg, id): if VERIFY: - VERIFY_ACTUAL.append(str(token.linenr) + ':' + id) + VERIFY_ACTUAL.append(str(token.linenr) + ':cert-' + id) else: - msg = '[' + token.file + ':' + str(token.linenr) + ']: (' + severity + ') ' + msg + ' [' + id + ']' - if CLI: - print(msg) - else: - sys.stderr.write(msg + '\n') + cppcheckdata.reportErrorCli(token, severity, msg, 'cert', id) def simpleMatch(token, pattern): for p in pattern.split(' '): @@ -121,7 +117,7 @@ def exp05(data): const1 = token.valueType.constness const2 = token.astOperand1.valueType.constness if (const1 % 2) < (const2 % 2): - reportError(token, 'style', "Attempt to cast away const", 'cert-EXP05-C') + reportError(token, 'style', "Attempt to cast away const", 'EXP05-C') elif token.str == '(' and token.astOperand1 and token.astOperand2 and token.astOperand1.function: function = token.astOperand1.function @@ -140,7 +136,7 @@ def exp05(data): continue const2 = arguments[argnr - 1].valueType.constness if (const2 % 2) == 1: - reportError(token, 'style', "Attempt to cast away const", 'cert-EXP05-C') + reportError(token, 'style', "Attempt to cast away const", 'EXP05-C') # EXP42-C @@ -160,7 +156,7 @@ def exp42(data): if isLocalUnpackedStruct(arg1) or isLocalUnpackedStruct(arg2): reportError( token, 'style', "Comparison of struct padding data " + - "(fix either by packing the struct using '#pragma pack' or by rewriting the comparison)", 'cert-EXP42-C') + "(fix either by packing the struct using '#pragma pack' or by rewriting the comparison)", 'EXP42-C') # EXP46-C @@ -170,7 +166,7 @@ def exp46(data): for token in data.tokenlist: if isBitwiseOp(token) and (isComparisonOp(token.astOperand1) or isComparisonOp(token.astOperand2)): reportError( - token, 'style', 'Bitwise operator is used with a Boolean-like operand', 'cert-EXP46-c') + token, 'style', 'Bitwise operator is used with a Boolean-like operand', 'EXP46-c') # INT31-C # Ensure that integer conversions do not result in lost or misinterpreted data @@ -204,7 +200,7 @@ def int31(data, platform): token, 'style', 'Ensure that integer conversions do not result in lost or misinterpreted data (casting ' + str(value.intvalue) + ' to unsigned ' + token.valueType.type + ')', - 'cert-INT31-c') + 'INT31-c') break if found: continue @@ -229,7 +225,7 @@ def int31(data, platform): token, 'style', 'Ensure that integer conversions do not result in lost or misinterpreted data (casting ' + str(value.intvalue) + ' to ' + destType + ')', - 'cert-INT31-c') + 'INT31-c') break # MSC30-C @@ -237,7 +233,7 @@ def int31(data, platform): def msc30(data): for token in data.tokenlist: if simpleMatch(token, "rand ( )") and isStandardFunction(token): - reportError(token, 'style', 'Do not use the rand() function for generating pseudorandom numbers', 'cert-MSC30-c') + reportError(token, 'style', 'Do not use the rand() function for generating pseudorandom numbers', 'MSC30-c') for arg in sys.argv[1:]: if arg == '-verify': diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 4352cd034..73c4b4a8a 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -9,6 +9,7 @@ License: No restrictions, use this as you need. import xml.etree.ElementTree as ET import argparse from fnmatch import fnmatch +import sys class Directive: @@ -851,3 +852,10 @@ def reportErrorXML(callstack, severity, message, errorId, suppressions, outputFu node.append(location) return ET.tostring(node, encoding="unicode") + +def reportErrorCli(token, severity, message, addon, errorId): + if '--cli' in sys.argv: + errout = sys.stdout + else: + errout = sys.errout + errout.write('[%s:%i]: (%s) %s [%s-%s]\n' % (token.file, int(token.linenr), severity, message, addon, errorId)) diff --git a/addons/misc.py b/addons/misc.py index c2be7cc74..86568c8e1 100644 --- a/addons/misc.py +++ b/addons/misc.py @@ -14,19 +14,14 @@ DEBUG = ('-debug' in sys.argv) VERIFY = ('-verify' in sys.argv) VERIFY_EXPECTED = [] VERIFY_ACTUAL = [] -CLI = ('--cli' in sys.argv) def reportError(token, severity, msg, id): if id == 'debug' and DEBUG == False: return if VERIFY: - VERIFY_ACTUAL.append(str(token.linenr) + ':' + id) + VERIFY_ACTUAL.append(str(token.linenr) + ':misc-' + id) else: - msg = '[' + token.file + ':' + str(token.linenr) + ']: (' + severity + ') ' + msg + ' [misc-' + id + ']' - if CLI: - print(msg) - else: - sys.stderr.write(msg + '\n') + cppcheckdata.reportErrorCli(token, severity, msg, 'misc', id) def simpleMatch(token, pattern): for p in pattern.split(' '): diff --git a/addons/threadsafety.py b/addons/threadsafety.py index 889ecd528..b72c077f4 100755 --- a/addons/threadsafety.py +++ b/addons/threadsafety.py @@ -7,10 +7,8 @@ import cppcheckdata import sys - def reportError(token, severity, msg, id): - sys.stderr.write( - '[' + token.file + ':' + str(token.linenr) + '] (' + severity + '): ' + msg + ' [' + id + ']\n') + cppcheckdata.reportErrorCli(token, severity, msg, 'threadsafety', id) def checkstatic(data):