Extend scope of afterCondition until end of function

This commit is contained in:
Paul 2020-06-29 11:55:59 -05:00
parent 7d9220e96c
commit 07d8cb4f01
2 changed files with 5 additions and 2 deletions

View File

@ -4232,7 +4232,10 @@ struct ValueFlowConditionHandler {
// TODO: constValue could be true if there are no assignments in the conditional blocks and
// perhaps if there are no && and no || in the condition
bool constValue = false;
forward(after, top->scope()->bodyEnd, cond.vartok, values, constValue);
const Scope* scope = top->scope();
while(scope->nestedIn && scope->type != Scope::eFunction)
scope = scope->nestedIn;
forward(after, scope->bodyEnd, cond.vartok, values, constValue);
}
}
}

View File

@ -262,7 +262,7 @@ private:
" }\n"
" tok->str();\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (warning, inconclusive) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", "", errout.str());
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok.\n", errout.str());
check("int foo(const Token *tok)\n"
"{\n"