MISRA: Prevent exception on variadic functions (#1436)

Functions with variadic arguments trip an exception in the MISRA checker
because some of the token is None and does not have some of the members
the code is expecting.

Prevent this by checking to see if the token is None and skipping the
code that tries to use that value.
This commit is contained in:
Richard A. Smith 2018-10-18 03:11:51 -04:00 committed by Daniel Marjamäki
parent b31b4706c5
commit 4dbdc934b8
1 changed files with 12 additions and 9 deletions

View File

@ -618,10 +618,11 @@ class MisraChecker:
def misra_5_2(self, data): def misra_5_2(self, data):
scopeVars = {} scopeVars = {}
for var in data.variables: for var in data.variables:
if var.nameToken.scope not in scopeVars: if var.nameToken is not None:
scopeVars.setdefault(var.nameToken.scope, {})["varlist"] = [] if var.nameToken.scope not in scopeVars:
scopeVars.setdefault(var.nameToken.scope, {})["scopelist"] = [] scopeVars.setdefault(var.nameToken.scope, {})["varlist"] = []
scopeVars[var.nameToken.scope]["varlist"].append(var) scopeVars.setdefault(var.nameToken.scope, {})["scopelist"] = []
scopeVars[var.nameToken.scope]["varlist"].append(var)
for scope in data.scopes: for scope in data.scopes:
if scope.nestedIn and scope.className: if scope.nestedIn and scope.className:
if scope.nestedIn not in scopeVars: if scope.nestedIn not in scopeVars:
@ -664,9 +665,10 @@ class MisraChecker:
enum = [] enum = []
scopeVars = {} scopeVars = {}
for var in data.variables: for var in data.variables:
if var.nameToken.scope not in scopeVars: if var.nameToken is not None:
scopeVars[var.nameToken.scope] = [] if var.nameToken.scope not in scopeVars:
scopeVars[var.nameToken.scope].append(var) scopeVars[var.nameToken.scope] = []
scopeVars[var.nameToken.scope].append(var)
for innerScope in data.scopes: for innerScope in data.scopes:
if innerScope.type == "Enum": if innerScope.type == "Enum":
enum_token = innerScope.bodyStart.next enum_token = innerScope.bodyStart.next
@ -760,8 +762,9 @@ class MisraChecker:
macroNames.append(res.group(1)) macroNames.append(res.group(1))
for var in data.variables: for var in data.variables:
for macro in macroNames: for macro in macroNames:
if var.nameToken.str[:31] == macro[:31]: if var.nameToken is not None:
self.reportError(var.nameToken, 5, 5) if var.nameToken.str[:31] == macro[:31]:
self.reportError(var.nameToken, 5, 5)
for scope in data.scopes: for scope in data.scopes:
for macro in macroNames: for macro in macroNames:
if scope.className and scope.className[:31] == macro[:31]: if scope.className and scope.className[:31] == macro[:31]: