Fixed #5874 (False positive: 'opposite conditions in nested if' with arrays)
This commit is contained in:
parent
92759dfd9d
commit
70b4c945de
|
@ -3345,6 +3345,13 @@ void CheckOther::oppositeInnerCondition()
|
|||
(!tok->varId() && nonlocal)) {
|
||||
if (Token::Match(tok, "%var% ++|--|="))
|
||||
break;
|
||||
if (Token::Match(tok,"%var% [")) {
|
||||
const Token *tok2 = tok->linkAt(1);
|
||||
while (Token::simpleMatch(tok2, "] ["))
|
||||
tok2 = tok2->linkAt(1);
|
||||
if (Token::simpleMatch(tok2, "] ="))
|
||||
break;
|
||||
}
|
||||
if (Token::Match(tok->previous(), "++|--|& %var%"))
|
||||
break;
|
||||
if (Token::Match(tok->previous(), "[(,] %var% [,)]")) {
|
||||
|
|
|
@ -448,6 +448,16 @@ private:
|
|||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5874 - array
|
||||
check("void testOppositeConditions2() {\n"
|
||||
" int array[2] = { 0, 0 };\n"
|
||||
" if (array[0] < 2) {\n"
|
||||
" array[0] += 5;\n"
|
||||
" if (array[0] > 2) {}\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void emptyBrackets() {
|
||||
|
|
Loading…
Reference in New Issue