From 3c48e08e6cad7b9b69896648090fad8157ecb7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 19 Apr 2018 22:23:34 +0200 Subject: [PATCH] misc.py: write debug message when valueType is None --- addons/misc.py | 29 ++++++++++++++++++++++++++--- addons/test/misc-test.cpp | 3 ++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/addons/misc.py b/addons/misc.py index 06cb3aae3..4a19bb56a 100644 --- a/addons/misc.py +++ b/addons/misc.py @@ -10,11 +10,14 @@ import cppcheckdata import sys import re +DEBUG = ('-debug' in sys.argv) VERIFY = ('-verify' in sys.argv) VERIFY_EXPECTED = [] VERIFY_ACTUAL = [] def reportError(token, severity, msg, id): + if id == 'debug' and DEBUG == False: + return if VERIFY: VERIFY_ACTUAL.append(str(token.linenr) + ':' + id) else: @@ -86,6 +89,10 @@ def ellipsisStructArg(data): continue if tok.astOperand1 is None or tok.astOperand2 is None: continue + if tok.astOperand2.str != ',': + continue + if tok.scope.type in ['Global', 'Class']: + continue if tok.astOperand1.function is None: continue for argnr, argvar in tok.astOperand1.function.argument.items(): @@ -96,17 +103,33 @@ def ellipsisStructArg(data): callArgs = getArguments(tok) for i in range(argnr-1, len(callArgs)): valueType = callArgs[i].valueType - if not valueType: + if valueType is None: + argStart = callArgs[i].previous + while argStart.str != ',': + if argStart.str == ')': + argStart = argStart.link + argStart = argStart.previous + argEnd = callArgs[i] + while argEnd.str != ',' and argEnd.str != ')': + if argEnd.str == '(': + argEnd = argEnd.link + argEnd = argEnd.next + expression = '' + argStart = argStart.next + while argStart != argEnd: + expression = expression + argStart.str + argStart = argStart.next + reportError(tok, 'debug', 'Bailout, unknown argument type for argument \'' + expression + '\'.', 'debug') continue if valueType.pointer > 0: continue - if valueType.type != 'record': + if valueType.type != 'record' and valueType.type != 'container': continue reportError(tok, 'style', 'Passing record to ellipsis function \'' + tok.astOperand1.function.name + '\'.', 'ellipsisStructArg') break for arg in sys.argv[1:]: - if arg == '-verify': + if arg in ['-debug', '-verify']: continue print('Checking ' + arg + '...') data = cppcheckdata.parsedump(arg) diff --git a/addons/test/misc-test.cpp b/addons/test/misc-test.cpp index c2d1b1206..f0f2cef17 100644 --- a/addons/test/misc-test.cpp +++ b/addons/test/misc-test.cpp @@ -33,6 +33,7 @@ class derived : base { // Pass struct to ellipsis function struct {int x;int y;} s; void ellipsis(int x, ...); -void foo(void) { +void foo(std::vector v) { ellipsis(321, s); // ellipsisStructArg + ellipsis(321, v[0]); // ellipsisStructArg }