Fixed #10583 (False positive: misra-15.6)

This commit is contained in:
Daniel Marjamäki 2021-11-15 21:27:36 +01:00
parent 88042773ce
commit 4f9a563570
2 changed files with 43 additions and 6 deletions

View File

@ -2832,14 +2832,41 @@ class MisraChecker:
state = 0
indent = 0
tok1 = None
def tokAt(tok,i):
while i < 0 and tok:
tok = tok.previous
if tok.str.startswith('//') or tok.str.startswith('/*'):
continue
i += 1
while i > 0 and tok:
tok = tok.next
if tok.str.startswith('//') or tok.str.startswith('/*'):
continue
i -= 1
return tok
def strtokens(tok, i1, i2):
tok1 = tokAt(tok, i1)
tok2 = tokAt(tok, i2)
tok = tok1
s = ''
while tok != tok2:
if tok.str.startswith('//') or tok.str.startswith('/*'):
tok = tok.next
continue
s += ' ' + tok.str
tok = tok.next
s += ' ' + tok.str
return s[1:]
for token in rawTokens:
if token.str in ['if', 'for', 'while']:
if simpleMatch(token.previous, '# if'):
if strtokens(token,-1,0) == '# if':
continue
if simpleMatch(token.previous, "} while"):
if strtokens(token,-1,0) == "} while":
# is there a 'do { .. } while'?
start = rawlink(token.previous)
if start and simpleMatch(start.previous, 'do {'):
start = rawlink(tokAt(token,-1))
if start and strtokens(start, -1, 0) == 'do {':
continue
if state == 2:
self.reportError(tok1, 15, 6)
@ -2847,9 +2874,9 @@ class MisraChecker:
indent = 0
tok1 = token
elif token.str == 'else':
if simpleMatch(token.previous, '# else'):
if strtokens(token,-1,0) == '# else':
continue
if simpleMatch(token, 'else if'):
if strtokens(token,0,1) == 'else if':
continue
if state == 2:
self.reportError(tok1, 15, 6)

View File

@ -1414,6 +1414,16 @@ static void misra_15_6(void) {
do {} while (x<0); // no-warning
}
static void misra_15_6_fp(void)
{
uint8_t value = 0U;
do // Test
{
value++;
}
while (value < 2U);
}
#if defined(M_20_9) && M_20_9 > 1 // no-warning (#10380)
#endif