Fixed #5874 (False positive: 'opposite conditions in nested if' with arrays)

This commit is contained in:
Daniel Marjamäki 2014-05-30 19:19:24 +02:00
parent 92759dfd9d
commit 70b4c945de
2 changed files with 17 additions and 0 deletions

View File

@ -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% [,)]")) {

View File

@ -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() {