misra: implement rule 22.5

This commit is contained in:
Daniel Marjamäki 2021-07-07 23:00:12 +02:00
parent cf049cb759
commit 4ecf3ccd17
3 changed files with 19 additions and 1 deletions

View File

@ -346,6 +346,11 @@ class Token:
return value.intvalue
return None
def isUnaryOp(self, op):
return self.astOperand1 and (self.astOperand2 is None) and self.str == op
def isBinaryOp(self):
return self.astOperand1 and self.astOperand2
class Scope:
"""

View File

@ -2872,6 +2872,13 @@ class MisraChecker:
'fetestexcept')):
self.reportError(token, 21, 12)
def misra_22_5(self, cfg):
for token in cfg.tokenlist:
if token.isUnaryOp("*") or (token.isBinaryOp() and token.str == '.'):
fileptr = token.astOperand1
if fileptr.variable and cppcheckdata.simpleMatch(fileptr.variable.typeStartToken, 'FILE *'):
self.reportError(token, 22, 5)
def get_verify_expected(self):
"""Return the list of expected violations in the verify test"""
return self.verify_expected
@ -3414,6 +3421,7 @@ class MisraChecker:
self.executeCheck(2111, self.misra_21_11, cfg)
self.executeCheck(2112, self.misra_21_12, cfg)
# 22.4 is already covered by Cppcheck writeReadOnlyFile
self.executeCheck(2205, self.misra_22_5, cfg)
def analyse_ctu_info(self, files):
all_typedef_info = []

View File

@ -45,7 +45,7 @@
typedef struct {
union { // 19.2
struct {
unsigned a : 2;
unsigned a : 2; // 8.1
unsigned : 14;
};
uint16_t value;
@ -1698,3 +1698,8 @@ static uint8_t misra_13_1_large_bad[1024] = { // 13.1
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
void misra_22_5(FILE *f) {
int x = *f; // 22.5
int y = f->pos; // 22.5
}