ValueFlow: Fixed false positives after escape scope

This commit is contained in:
Daniel Marjamäki 2019-10-20 20:57:16 +02:00
parent 223ceeb97f
commit 78c02f0505
2 changed files with 10 additions and 2 deletions

View File

@ -2610,7 +2610,7 @@ static bool valueFlowForwardVariable(Token* const startToken,
// goto '}'
tok2 = startToken1->link();
if (isReturnScope(tok2, settings) || !vfresult) {
if (isEscapeScope(startToken1, tokenlist, true) || !vfresult) {
if (condAlwaysTrue)
return false;
removeValues(values, truevalues);
@ -2638,7 +2638,7 @@ static bool valueFlowForwardVariable(Token* const startToken,
// goto '}'
tok2 = startTokenElse->link();
if (isReturnScope(tok2, settings) || !vfresult) {
if (isEscapeScope(startTokenElse, tokenlist, true) || !vfresult) {
if (condAlwaysFalse)
return false;
removeValues(values, falsevalues);

View File

@ -551,6 +551,14 @@ private:
" IF(!fred){}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" BUFFER *buffer = get_buffer();\n"
" if (!buffer)\n"
" uv_fatal_error();\n"
" buffer->x = 11;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Dereferencing a pointer and then checking if it is null