From f85f3c28e1f980dc3f138b9df17db5c6612d0dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 30 Jul 2021 15:53:10 +0200 Subject: [PATCH] misra; implement rule 21.15 --- addons/cppcheckdata.py | 2 ++ addons/misra.py | 18 ++++++++++++++++++ addons/test/misra/misra-test.c | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 24d9c642d..27d9e1014 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -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 diff --git a/addons/misra.py b/addons/misra.py index a1291b9c0..6ffb92933 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -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) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 4b2321171..40f78dbcb 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -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,