misra: implement rule 22.7

This commit is contained in:
Daniel Marjamäki 2021-08-15 12:04:55 +02:00
parent 6a565f9e2f
commit 10c2dcf721
2 changed files with 21 additions and 0 deletions

View File

@ -3463,6 +3463,21 @@ class MisraChecker:
if fileptr.variable and cppcheckdata.simpleMatch(fileptr.variable.typeStartToken, 'FILE *'):
self.reportError(token, 22, 5)
def misra_22_7(self, cfg):
for eofToken in cfg.tokenlist:
if eofToken.str != 'EOF':
continue
if eofToken.astParent is None or not eofToken.astParent.isComparisonOp:
continue
if eofToken.astParent.astOperand1 == eofToken:
eofTokenSibling = eofToken.astParent.astOperand2
else:
eofTokenSibling = eofToken.astParent.astOperand1
while isCast(eofTokenSibling) and eofTokenSibling.valueType and eofTokenSibling.valueType.type and eofTokenSibling.valueType.type == 'int':
eofTokenSibling = eofTokenSibling.astOperand2 if eofTokenSibling.astOperand2 else eofTokenSibling.astOperand1
if eofTokenSibling is not None and eofTokenSibling.valueType and eofTokenSibling.valueType and eofTokenSibling.valueType.type in ('bool', 'char', 'short'):
self.reportError(eofToken, 22, 7)
def misra_22_8(self, cfg):
is_zero = False
for token in cfg.tokenlist:
@ -4080,6 +4095,7 @@ class MisraChecker:
self.executeCheck(2115, self.misra_21_15, cfg)
# 22.4 is already covered by Cppcheck writeReadOnlyFile
self.executeCheck(2205, self.misra_22_5, cfg)
self.executeCheck(2207, self.misra_22_7, cfg)
self.executeCheck(2208, self.misra_22_8, cfg)
self.executeCheck(2209, self.misra_22_9, cfg)
self.executeCheck(2210, self.misra_22_10, cfg)

View File

@ -1787,6 +1787,11 @@ static void misra_22_5(FILE *f) {
int y = f->pos; // 22.5
}
static void misra_22_7(char ch)
{
if (EOF == ch) {} // 22.7
}
static void misra_22_8(void)
{
(void)strtoll("123", NULL, 10); // 22.8