MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / misra_config

Method misra_config

addons/misra.py:3511–3565  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

3509 self.reportError(token, 17, 3)
3510
3511 def misra_config(self, data):
3512 for var in data.variables:
3513 if not var.isArray or var.nameToken is None or not cppcheckdata.simpleMatch(var.nameToken.next, '['):
3514 continue
3515 tok = var.nameToken.next
3516 while tok.str == '[':
3517 sz = tok.astOperand2
3518 if sz and sz.getKnownIntValue() is None:
3519 has_var = False
3520 unknown_constant = False
3521 tokens = [sz]
3522 while len(tokens) > 0:
3523 t = tokens[-1]
3524 tokens = tokens[:-1]
3525 if t:
3526 if t.isName and t.getKnownIntValue() is None:
3527 if t.varId or t.variable:
3528 has_var = True
3529 continue
3530 unknown_constant = True
3531 self.report_config_error(tok, 'Unknown constant {}, please review configuration'.format(t.str))
3532 if t.isArithmeticalOp:
3533 tokens += [t.astOperand1, t.astOperand2]
3534 if not unknown_constant and not has_var:
3535 self.report_config_error(tok, 'Unknown array size, please review configuration')
3536 tok = tok.link.next
3537
3538 for token in data.tokenlist:
3539 if token.str not in ("while", "if"):
3540 continue
3541 tok = token.next
3542 if token is None or tok.str != "(":
3543 continue
3544 end_token = tok.link
3545 while tok != end_token:
3546 tok = tok.next
3547 if tok.str == 'sizeof' and tok.next.str == '(':
3548 tok = tok.next.link
3549 continue
3550 if tok.str == "(" and tok.isCast:
3551 tok = tok.link
3552 continue
3553 if not tok.isName:
3554 continue
3555 if tok.function or tok.variable or tok.varId or tok.valueType or tok.typeScope:
3556 continue
3557 if tok.next.str == "(" or tok.str in ["EOF"]:
3558 continue
3559 if isKeyword(tok.str, data.standards.c) or isStdLibId(tok.str, data.standards.c):
3560 continue
3561 if tok.astParent is None:
3562 continue
3563 if tok.astParent.str == "." and tok.astParent.valueType:
3564 continue
3565 self.report_config_error(tok, "Variable '%s' is unknown" % tok.str)
3566
3567 def misra_17_6(self, rawTokens):
3568 for token in rawTokens:

Callers 1

parseDumpMethod · 0.95

Calls 6

report_config_errorMethod · 0.95
isStdLibIdFunction · 0.85
simpleMatchMethod · 0.80
getKnownIntValueMethod · 0.80
formatMethod · 0.80
isKeywordFunction · 0.70

Tested by

no test coverage detected