Revert "Revert "Add MISRA 18.4 check (#1966)""

This reverts commit 9b674fa306.
This commit is contained in:
Daniel Marjamäki 2019-07-09 15:57:12 +02:00
parent 4eb362352d
commit 29f5f59242
2 changed files with 27 additions and 0 deletions

View File

@ -1612,6 +1612,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:
@ -2305,6 +2317,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)

View File

@ -506,6 +506,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
}