Fix issue 9268: false negative: (style) Condition '...' is always true (#2080)
* Fix issue 9268: false negative: (style) Condition '...' is always true * Fix copy and paste mistake
This commit is contained in:
parent
13df5b2413
commit
0c1dff5c93
|
@ -3911,6 +3911,7 @@ struct ValueFlowConditionHandler {
|
|||
startTokens[1] = top->link()->linkAt(1)->tokAt(2);
|
||||
|
||||
bool bail = false;
|
||||
const bool bothCanBeKnown = check_if && check_else && !Token::Match(tok->astParent(), "&&|%oror%");
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
const Token *const startToken = startTokens[i];
|
||||
|
@ -3918,6 +3919,8 @@ struct ValueFlowConditionHandler {
|
|||
continue;
|
||||
std::list<ValueFlow::Value> &values = (i == 0 ? cond.true_values : cond.false_values);
|
||||
valueFlowSetConditionToKnown(tok, values, i == 0);
|
||||
if (bothCanBeKnown)
|
||||
valueFlowSetConditionToKnown(tok, values, i != 0);
|
||||
|
||||
bool changed = forward(startTokens[i], startTokens[i]->link(), var, values, true);
|
||||
values.front().setPossible();
|
||||
|
|
|
@ -3197,6 +3197,15 @@ private:
|
|||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'array' is always true\n", errout.str());
|
||||
|
||||
check("void f(int *array, int size ) {\n"
|
||||
" for(int i = 0; i < size; ++i) {\n"
|
||||
" if(array == 0)\n"
|
||||
" continue;\n"
|
||||
" else if(array){}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'array' is always true\n", errout.str());
|
||||
}
|
||||
|
||||
void multiConditionAlwaysTrue() {
|
||||
|
|
Loading…
Reference in New Issue