diff --git a/addons/misra.py b/addons/misra.py index bdfde1ae0..e3b3802e3 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -2150,7 +2150,8 @@ class MisraChecker: self.reportError(token, 10, 2) if token.str == '-': - if getEssentialType(token.astOperand1).split(' ')[-1] != 'char': + e1 = getEssentialType(token.astOperand1) + if e1 and e1.split(' ')[-1] != 'char': self.reportError(token, 10, 2) if not isEssentiallyChar(token.astOperand2) and not isEssentiallySignedOrUnsigned(token.astOperand2): self.reportError(token, 10, 2) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 4f86d8231..66e29b724 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -677,6 +677,10 @@ static void misra_10_2(void) { res = s16a - 'a'; // 10.2 10.3 10.4 res = '0' + f32a; // 10.2 10.4 + + // 10481 - crash + char buf[1] = {'f'}; + x = buf[0] - '0'; } static void misra_10_3(uint32_t u32a, uint32_t u32b) {