diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 678744b89..3c507c98d 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -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: """ diff --git a/addons/misra.py b/addons/misra.py index 7e014004c..6f56f3b58 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -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 = [] diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 3fa935d76..80a600858 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -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 +}