CheckCondition::multiCondition2: Fix FN for pointers
This commit is contained in:
parent
095e435031
commit
d838dc2129
|
@ -494,9 +494,13 @@ void CheckCondition::multiCondition2()
|
||||||
if (cond->varId()) {
|
if (cond->varId()) {
|
||||||
vars.insert(cond->varId());
|
vars.insert(cond->varId());
|
||||||
const Variable *var = cond->variable();
|
const Variable *var = cond->variable();
|
||||||
nonlocal |= (var && (!var->isLocal() || var->isStatic()) && !var->isArgument());
|
if (!nonlocal && var) {
|
||||||
// TODO: if var is pointer check what it points at
|
if (!(var->isLocal() || var->isStatic() || var->isArgument()))
|
||||||
nonlocal |= (var && (var->isPointer() || var->isReference()));
|
nonlocal = true;
|
||||||
|
else if ((var->isPointer() || var->isReference()) && !Token::simpleMatch(cond->astParent(), "!"))
|
||||||
|
// TODO: if var is pointer check what it points at
|
||||||
|
nonlocal = true;
|
||||||
|
}
|
||||||
} else if (!nonlocal && cond->isName()) {
|
} else if (!nonlocal && cond->isName()) {
|
||||||
// varid is 0. this is possibly a nonlocal variable..
|
// varid is 0. this is possibly a nonlocal variable..
|
||||||
nonlocal = Token::Match(cond->astParent(), "%cop%|(|[");
|
nonlocal = Token::Match(cond->astParent(), "%cop%|(|[");
|
||||||
|
@ -534,7 +538,6 @@ void CheckCondition::multiCondition2()
|
||||||
sameConditionAfterEarlyExitError(cond1, cond2);
|
sameConditionAfterEarlyExitError(cond1, cond2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "%type% (") && nonlocal) // function call -> bailout if there are nonlocal variables
|
if (Token::Match(tok, "%type% (") && nonlocal) // function call -> bailout if there are nonlocal variables
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1452,6 +1452,7 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:7]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str());
|
||||||
|
|
||||||
|
// pointers...
|
||||||
check("void f(struct ABC *abc) {\n"
|
check("void f(struct ABC *abc) {\n"
|
||||||
" struct AB *ab = abc->ab;\n"
|
" struct AB *ab = abc->ab;\n"
|
||||||
" if (ab->a == 123){\n"
|
" if (ab->a == 123){\n"
|
||||||
|
@ -1463,6 +1464,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(const int *i) {\n"
|
||||||
|
" if (!i) return;\n"
|
||||||
|
" if (!num1tok) { *num1 = *num2; }\n"
|
||||||
|
" if (!i) {}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Same condition, second condition is always false\n", errout.str());
|
||||||
|
|
||||||
{
|
{
|
||||||
// #6095 - calling member function that might change the state
|
// #6095 - calling member function that might change the state
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
|
Loading…
Reference in New Issue