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)) {
|
(!tok->varId() && nonlocal)) {
|
||||||
if (Token::Match(tok, "%var% ++|--|="))
|
if (Token::Match(tok, "%var% ++|--|="))
|
||||||
break;
|
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%"))
|
if (Token::Match(tok->previous(), "++|--|& %var%"))
|
||||||
break;
|
break;
|
||||||
if (Token::Match(tok->previous(), "[(,] %var% [,)]")) {
|
if (Token::Match(tok->previous(), "[(,] %var% [,)]")) {
|
||||||
|
|
|
@ -448,6 +448,16 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void emptyBrackets() {
|
||||||
|
|
Loading…
Reference in New Issue