From cf8a5d9a229ecd9b28ced97e9b01dbbe093510b2 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Wed, 3 Feb 2021 03:21:47 -0600 Subject: [PATCH] Fix issue 10111: FP knownConditionTrueFalse (#3110) --- lib/valueflow.cpp | 4 ++++ test/testvalueflow.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index bf4c3487d..703679231 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -440,7 +440,11 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti // .empty, .size, +"abc", +'a' if (Token::Match(parent, "+|==|!=") && parent->astOperand1() && parent->astOperand2()) { for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) { + if (value1.isImpossible()) + continue; for (const ValueFlow::Value &value2 : parent->astOperand2()->values()) { + if (value2.isImpossible()) + continue; if (value1.path != value2.path) continue; ValueFlow::Value result; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8cd4cfd6f..e0fd9bd4c 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5026,6 +5026,17 @@ private: "}\n"; 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 g();\n" "int f(bool b) {\n" " std::set a;\n"