parent
77bfec4317
commit
083c4aa34b
|
@ -3259,23 +3259,26 @@ class MisraChecker:
|
||||||
|
|
||||||
def misra_config(self, data):
|
def misra_config(self, data):
|
||||||
for token in data.tokenlist:
|
for token in data.tokenlist:
|
||||||
if token.str not in ["while", "if"]:
|
if token.str not in ("while", "if"):
|
||||||
continue
|
|
||||||
if token.next.str != "(":
|
|
||||||
continue
|
continue
|
||||||
tok = token.next
|
tok = token.next
|
||||||
while tok != token.next.link:
|
if token is None or tok.str != "(":
|
||||||
|
continue
|
||||||
|
end_token = tok.link
|
||||||
|
while tok != end_token:
|
||||||
|
tok = tok.next
|
||||||
if tok.str == "(" and tok.isCast:
|
if tok.str == "(" and tok.isCast:
|
||||||
tok = tok.link
|
tok = tok.link
|
||||||
continue
|
continue
|
||||||
if not tok.isName or tok.function or tok.variable or tok.varId or tok.valueType \
|
if not tok.isName:
|
||||||
or tok.next.str == "(" or tok.str in ["EOF"] \
|
|
||||||
or isKeyword(tok.str) or isStdLibId(tok.str):
|
|
||||||
tok = tok.next
|
|
||||||
continue
|
continue
|
||||||
errmsg = tok.str + " Variable is unknown"
|
if tok.function or tok.variable or tok.varId or tok.valueType:
|
||||||
self.reportError(token, 0, 0, "config")
|
continue
|
||||||
break
|
if tok.next.str == "(" or tok.str in ["EOF"]:
|
||||||
|
continue
|
||||||
|
if isKeyword(tok.str) or isStdLibId(tok.str):
|
||||||
|
continue
|
||||||
|
self.report_config_error(tok, "Variable '%s' is unknown" % tok.str)
|
||||||
|
|
||||||
def misra_17_6(self, rawTokens):
|
def misra_17_6(self, rawTokens):
|
||||||
for token in rawTokens:
|
for token in rawTokens:
|
||||||
|
@ -4184,30 +4187,29 @@ class MisraChecker:
|
||||||
|
|
||||||
self.addSuppressedRule(ruleNum)
|
self.addSuppressedRule(ruleNum)
|
||||||
|
|
||||||
def reportError(self, location, num1, num2, other_id = None):
|
def report_config_error(self, location, errmsg):
|
||||||
if not other_id:
|
cppcheck_severity = 'error'
|
||||||
ruleNum = num1 * 100 + num2
|
error_id = 'config'
|
||||||
|
if self.settings.verify:
|
||||||
|
self.verify_actual.append('%s:%d %s' % (location.file, location.linenr, error_id))
|
||||||
else:
|
else:
|
||||||
ruleNum = other_id
|
cppcheckdata.reportError(location, cppcheck_severity, errmsg, 'misra', error_id)
|
||||||
|
|
||||||
|
def reportError(self, location, num1, num2):
|
||||||
|
ruleNum = num1 * 100 + num2
|
||||||
|
|
||||||
if self.isRuleGloballySuppressed(ruleNum):
|
if self.isRuleGloballySuppressed(ruleNum):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.settings.verify:
|
if self.settings.verify:
|
||||||
if not other_id:
|
self.verify_actual.append('%s:%d %d.%d' % (location.file, location.linenr, num1, num2))
|
||||||
self.verify_actual.append('%s:%d %d.%d' % (location.file, location.linenr, num1, num2))
|
|
||||||
else:
|
|
||||||
self.verify_actual.append('%s:%d %s' % (location.file, location.linenr, other_id))
|
|
||||||
elif self.isRuleSuppressed(location.file, location.linenr, ruleNum):
|
elif self.isRuleSuppressed(location.file, location.linenr, ruleNum):
|
||||||
# Error is suppressed. Ignore
|
# Error is suppressed. Ignore
|
||||||
self.suppressionStats.setdefault(ruleNum, 0)
|
self.suppressionStats.setdefault(ruleNum, 0)
|
||||||
self.suppressionStats[ruleNum] += 1
|
self.suppressionStats[ruleNum] += 1
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if not other_id:
|
errorId = 'c2012-' + str(num1) + '.' + str(num2)
|
||||||
errorId = 'c2012-' + str(num1) + '.' + str(num2)
|
|
||||||
else:
|
|
||||||
errorId = 'c2012-' + other_id
|
|
||||||
misra_severity = 'Undefined'
|
misra_severity = 'Undefined'
|
||||||
cppcheck_severity = 'style'
|
cppcheck_severity = 'style'
|
||||||
if ruleNum in self.ruleTexts:
|
if ruleNum in self.ruleTexts:
|
||||||
|
|
|
@ -17,6 +17,14 @@ from .util import dump_create, dump_remove, convert_json_output
|
||||||
TEST_SOURCE_FILES = ['./addons/test/misra/misra-test.c']
|
TEST_SOURCE_FILES = ['./addons/test/misra/misra-test.c']
|
||||||
|
|
||||||
|
|
||||||
|
def remove_misra_config(s:str):
|
||||||
|
ret = ''
|
||||||
|
for line in s.splitlines():
|
||||||
|
if '[misra-config]' not in line:
|
||||||
|
ret += line + '\n'
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def setup_module(module):
|
def setup_module(module):
|
||||||
for f in TEST_SOURCE_FILES:
|
for f in TEST_SOURCE_FILES:
|
||||||
dump_create(f)
|
dump_create(f)
|
||||||
|
@ -92,7 +100,7 @@ def test_rules_cppcheck_severity(checker, capsys):
|
||||||
checker.loadRuleTexts("./addons/test/misra/misra_rules_dummy.txt")
|
checker.loadRuleTexts("./addons/test/misra/misra_rules_dummy.txt")
|
||||||
checker.parseDump("./addons/test/misra/misra-test.c.dump")
|
checker.parseDump("./addons/test/misra/misra-test.c.dump")
|
||||||
captured = capsys.readouterr().err
|
captured = capsys.readouterr().err
|
||||||
assert("(error)" not in captured)
|
assert("(error)" not in remove_misra_config(captured))
|
||||||
assert("(warning)" not in captured)
|
assert("(warning)" not in captured)
|
||||||
assert("(style)" in captured)
|
assert("(style)" in captured)
|
||||||
|
|
||||||
|
@ -101,7 +109,7 @@ def test_rules_cppcheck_severity_custom(checker, capsys):
|
||||||
checker.setSeverity("custom-severity")
|
checker.setSeverity("custom-severity")
|
||||||
checker.parseDump("./addons/test/misra/misra-test.c.dump")
|
checker.parseDump("./addons/test/misra/misra-test.c.dump")
|
||||||
captured = capsys.readouterr().err
|
captured = capsys.readouterr().err
|
||||||
assert("(error)" not in captured)
|
assert("(error)" not in remove_misra_config(captured))
|
||||||
assert("(warning)" not in captured)
|
assert("(warning)" not in captured)
|
||||||
assert("(style)" not in captured)
|
assert("(style)" not in captured)
|
||||||
assert("(custom-severity)" in captured)
|
assert("(custom-severity)" in captured)
|
||||||
|
|
|
@ -45,6 +45,7 @@ const std::set<std::string> ErrorLogger::mCriticalErrorIds{
|
||||||
"internalAstError",
|
"internalAstError",
|
||||||
"instantiationError",
|
"instantiationError",
|
||||||
"internalError",
|
"internalError",
|
||||||
|
"misra-config",
|
||||||
"premium-internalError",
|
"premium-internalError",
|
||||||
"premium-invalidArgument",
|
"premium-invalidArgument",
|
||||||
"premium-invalidLicense",
|
"premium-invalidLicense",
|
||||||
|
|
Loading…
Reference in New Issue