misra: implement rule 22.5
This commit is contained in:
parent
cf049cb759
commit
4ecf3ccd17
|
@ -346,6 +346,11 @@ class Token:
|
||||||
return value.intvalue
|
return value.intvalue
|
||||||
return None
|
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:
|
class Scope:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2872,6 +2872,13 @@ class MisraChecker:
|
||||||
'fetestexcept')):
|
'fetestexcept')):
|
||||||
self.reportError(token, 21, 12)
|
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):
|
def get_verify_expected(self):
|
||||||
"""Return the list of expected violations in the verify test"""
|
"""Return the list of expected violations in the verify test"""
|
||||||
return self.verify_expected
|
return self.verify_expected
|
||||||
|
@ -3414,6 +3421,7 @@ class MisraChecker:
|
||||||
self.executeCheck(2111, self.misra_21_11, cfg)
|
self.executeCheck(2111, self.misra_21_11, cfg)
|
||||||
self.executeCheck(2112, self.misra_21_12, cfg)
|
self.executeCheck(2112, self.misra_21_12, cfg)
|
||||||
# 22.4 is already covered by Cppcheck writeReadOnlyFile
|
# 22.4 is already covered by Cppcheck writeReadOnlyFile
|
||||||
|
self.executeCheck(2205, self.misra_22_5, cfg)
|
||||||
|
|
||||||
def analyse_ctu_info(self, files):
|
def analyse_ctu_info(self, files):
|
||||||
all_typedef_info = []
|
all_typedef_info = []
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union { // 19.2
|
union { // 19.2
|
||||||
struct {
|
struct {
|
||||||
unsigned a : 2;
|
unsigned a : 2; // 8.1
|
||||||
unsigned : 14;
|
unsigned : 14;
|
||||||
};
|
};
|
||||||
uint16_t value;
|
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,
|
||||||
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue