Fix #9505 (MISRA 20.7 check suggests code change that leads to invalid code)

This commit is contained in:
Daniel Marjamäki 2019-12-08 20:07:52 +01:00
parent 61c2c5a5f0
commit 3d3e6f384c
2 changed files with 10 additions and 7 deletions

View File

@ -1822,21 +1822,23 @@ class MisraChecker:
pos = exp.find(arg, pos)
if pos < 0:
break
# is 'arg' used at position pos
pos1 = pos - 1
pos2 = pos + len(arg)
pos = pos2
if isalnum(exp[pos1]) or exp[pos1] == '_':
if pos1 >= 0 and (isalnum(exp[pos1]) or exp[pos1] == '_'):
continue
if isalnum(exp[pos2]) or exp[pos2] == '_':
if pos2 < len(exp) and (isalnum(exp[pos2]) or exp[pos2] == '_'):
continue
while exp[pos1] == ' ':
while pos1 >= 0 and exp[pos1] == ' ':
pos1 -= 1
if exp[pos1] != '(' and exp[pos1] != '[':
if exp[pos1] not in '([#':
self.reportError(directive, 20, 7)
break
while exp[pos2] == ' ':
while pos2 < len(exp) and exp[pos2] == ' ':
pos2 += 1
if exp[pos2] != ')' and exp[pos2] != ']':
if pos2 < len(exp) and exp[pos2] not in ')]#':
self.reportError(directive, 20, 7)
break

View File

@ -754,8 +754,9 @@ union misra_19_2 { }; // 19.2
#define M_20_7_1(A) (A+1) // 20.7
#define M_20_7_2(A,B) (1+AB+2) // no warning
#define M_20_7_3(A) ((A)+A) // 20.7
#define M_20_7_4(A) x##A // 20.10 this test was written to see there are not FPs
#define STRINGIFY(a) (#a) // 20.7 20.10
#define M_20_10(a) (#a) // 20.10
#else1 // 20.13