Fix issue 10111: FP knownConditionTrueFalse (#3110)

This commit is contained in:
Paul Fultz II 2021-02-03 03:21:47 -06:00 committed by GitHub
parent b003c82650
commit cf8a5d9a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -440,7 +440,11 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
// .empty, .size, +"abc", +'a' // .empty, .size, +"abc", +'a'
if (Token::Match(parent, "+|==|!=") && parent->astOperand1() && parent->astOperand2()) { if (Token::Match(parent, "+|==|!=") && parent->astOperand1() && parent->astOperand2()) {
for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) { for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) {
if (value1.isImpossible())
continue;
for (const ValueFlow::Value &value2 : parent->astOperand2()->values()) { for (const ValueFlow::Value &value2 : parent->astOperand2()->values()) {
if (value2.isImpossible())
continue;
if (value1.path != value2.path) if (value1.path != value2.path)
continue; continue;
ValueFlow::Value result; ValueFlow::Value result;

View File

@ -5026,6 +5026,17 @@ private:
"}\n"; "}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0)); ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0));
code = "bool f(std::string s) {\n"
" if (!s.empty()) {\n"
" bool x = s == \"0\";\n"
" return x;\n"
" }\n"
" return false;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 0));
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0));
code = "std::vector<int> g();\n" code = "std::vector<int> g();\n"
"int f(bool b) {\n" "int f(bool b) {\n"
" std::set<int> a;\n" " std::set<int> a;\n"