misra; implement rule 21.15

This commit is contained in:
Daniel Marjamäki 2021-07-30 15:53:10 +02:00
parent 6a81b4c17c
commit f85f3c28e1
3 changed files with 26 additions and 0 deletions

View File

@ -1287,6 +1287,8 @@ def get_function_call_name_args(token):
return None, None
if token.function:
nametok = token.function.token
if nametok is None:
nametok = token.function.tokenDef
if token in (token.function.token, token.function.tokenDef):
return None, None
name = nametok.str

View File

@ -3429,6 +3429,23 @@ class MisraChecker:
'fetestexcept')):
self.reportError(token, 21, 12)
def misra_21_15(self, data):
for token in data.tokenlist:
if token.str not in ('memcpy', 'memmove', 'memcmp'):
continue
name, args = cppcheckdata.get_function_call_name_args(token)
if name is None:
continue
if len(args) != 3:
continue
if args[0].valueType is None or args[1].valueType is None:
continue
if args[0].valueType.type == args[1].valueType.type:
continue
if args[0].valueType.type == 'void' or args[1].valueType.type == 'void':
continue
self.reportError(token, 21, 15)
def misra_22_5(self, cfg):
for token in cfg.tokenlist:
if token.isUnaryOp("*") or (token.isBinaryOp() and token.str == '.'):
@ -4002,6 +4019,7 @@ class MisraChecker:
self.executeCheck(2110, self.misra_21_10, cfg)
self.executeCheck(2111, self.misra_21_11, cfg)
self.executeCheck(2112, self.misra_21_12, cfg)
self.executeCheck(2115, self.misra_21_15, cfg)
# 22.4 is already covered by Cppcheck writeReadOnlyFile
self.executeCheck(2205, self.misra_22_5, cfg)

View File

@ -1641,6 +1641,12 @@ static void misra_21_12(void) {
rc = fetestexcept(1); // 21.12
}
static void misra_21_15(uint8_t *x, uint16_t *y) {
(void)memcpy(x, y, 10); // 21.15
(void)memmove(x, y, 10); // 21.15
(void)memcmp(x, y, 10); // 21.15
}
// Large arrays for R13.1. Size exceeds default Python's max recursion depth.
static uint8_t misra_13_1_large_ok[1024] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,