Skip to content

Commit f85f3c2

Browse files
committed
misra; implement rule 21.15
1 parent 6a81b4c commit f85f3c2

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

addons/cppcheckdata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ def get_function_call_name_args(token):
12871287
return None, None
12881288
if token.function:
12891289
nametok = token.function.token
1290+
if nametok is None:
1291+
nametok = token.function.tokenDef
12901292
if token in (token.function.token, token.function.tokenDef):
12911293
return None, None
12921294
name = nametok.str

addons/misra.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,23 @@ def misra_21_12(self, data):
34293429
'fetestexcept')):
34303430
self.reportError(token, 21, 12)
34313431

3432+
def misra_21_15(self, data):
3433+
for token in data.tokenlist:
3434+
if token.str not in ('memcpy', 'memmove', 'memcmp'):
3435+
continue
3436+
name, args = cppcheckdata.get_function_call_name_args(token)
3437+
if name is None:
3438+
continue
3439+
if len(args) != 3:
3440+
continue
3441+
if args[0].valueType is None or args[1].valueType is None:
3442+
continue
3443+
if args[0].valueType.type == args[1].valueType.type:
3444+
continue
3445+
if args[0].valueType.type == 'void' or args[1].valueType.type == 'void':
3446+
continue
3447+
self.reportError(token, 21, 15)
3448+
34323449
def misra_22_5(self, cfg):
34333450
for token in cfg.tokenlist:
34343451
if token.isUnaryOp("*") or (token.isBinaryOp() and token.str == '.'):
@@ -4002,6 +4019,7 @@ def fillVerifyExpected(verify_expected, tok):
40024019
self.executeCheck(2110, self.misra_21_10, cfg)
40034020
self.executeCheck(2111, self.misra_21_11, cfg)
40044021
self.executeCheck(2112, self.misra_21_12, cfg)
4022+
self.executeCheck(2115, self.misra_21_15, cfg)
40054023
# 22.4 is already covered by Cppcheck writeReadOnlyFile
40064024
self.executeCheck(2205, self.misra_22_5, cfg)
40074025

addons/test/misra/misra-test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,12 @@ static void misra_21_12(void) {
16411641
rc = fetestexcept(1); // 21.12
16421642
}
16431643

1644+
static void misra_21_15(uint8_t *x, uint16_t *y) {
1645+
(void)memcpy(x, y, 10); // 21.15
1646+
(void)memmove(x, y, 10); // 21.15
1647+
(void)memcmp(x, y, 10); // 21.15
1648+
}
1649+
16441650
// Large arrays for R13.1. Size exceeds default Python's max recursion depth.
16451651
static uint8_t misra_13_1_large_ok[1024] = {
16461652
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,

0 commit comments

Comments
 (0)