From 3ff7ef091829835be19f268310ad5a10a392e7f4 Mon Sep 17 00:00:00 2001 From: Georgy Komarov Date: Sun, 7 Jul 2019 22:54:08 +0300 Subject: [PATCH] Add MISRA 18.4 check (#1966) * Add MISRA 18.4 check * Fixup * Quickfix --- addons/misra.py | 13 +++++++++++++ addons/test/misra-test.c | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/addons/misra.py b/addons/misra.py index bec397672..585eb40fe 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1611,6 +1611,18 @@ class MisraChecker: if var and var.isArgument: self.reportError(token, 17, 8) + def misra_18_4(self, data): + for token in data.tokenlist: + if not token.str in ('+', '-', '+=', '-='): + continue + if token.astOperand1 is None or token.astOperand2 is None: + continue + vt1 = token.astOperand1.valueType + vt2 = token.astOperand2.valueType + if vt1 and vt1.pointer > 0: + self.reportError(token, 18, 4) + elif vt2 and vt2.pointer > 0: + self.reportError(token, 18, 4) def misra_18_5(self, data): for var in data.variables: @@ -2304,6 +2316,7 @@ class MisraChecker: self.misra_17_6(data.rawTokens) self.misra_17_7(cfg) self.misra_17_8(cfg) + self.misra_18_4(cfg) self.misra_18_5(cfg) self.misra_18_7(cfg) self.misra_18_8(cfg) diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index bf12361e0..82e90abcd 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -503,6 +503,20 @@ void misra_17_8(int x) { x = 3; // 17.8 } +void misra_18_4() +{ + int b = 42; + int *bp = &b; + bp += 1; // 18.4 + bp -= 2; // 18.4 + int *p = bp - 2; // 18.4 + int *ab = &b + 1; // 18.4 + p = bp + p; // 18.4 + bp = 1 + p + 1; // 18.4 + b += 19; // no-warning + b = b + 9; // no-warning +} + void misra_18_5() { int *** p; // 18.5 }