Fix 10787: False positive: knownConditionTrueFalse with a conditional exit (#3804)

This commit is contained in:
Paul Fultz II 2022-02-06 13:13:44 -06:00 committed by GitHub
parent fa776051e9
commit a639c59780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -1439,6 +1439,8 @@ void SymbolDatabase::createSymbolDatabaseEscapeFunctions()
Function * function = scope.function;
if (!function)
continue;
if (Token::findsimplematch(scope.bodyStart, "return", scope.bodyEnd))
continue;
function->isEscapeFunction(isReturnScope(scope.bodyEnd, &mSettings->library, nullptr, true));
}
}

View File

@ -3133,6 +3133,19 @@ private:
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 8U, 1));
ASSERT_EQUALS(false, testValueOfXImpossible(code, 8U, 1));
code = "void g(int i) {\n"
" if (i == 1)\n"
" return;\n"
" abort();\n"
"}\n"
"int f(int x) {\n"
" if (x != 0)\n"
" g(x);\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 9U, 0));
ASSERT_EQUALS(true, testValueOfX(code, 9U, 0));
}
void valueFlowAfterConditionExpr() {