Skip to content

Commit cf8a5d9

Browse files
authored
Fix issue 10111: FP knownConditionTrueFalse (#3110)
1 parent b003c82 commit cf8a5d9

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,11 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
440440
// .empty, .size, +"abc", +'a'
441441
if (Token::Match(parent, "+|==|!=") && parent->astOperand1() && parent->astOperand2()) {
442442
for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) {
443+
if (value1.isImpossible())
444+
continue;
443445
for (const ValueFlow::Value &value2 : parent->astOperand2()->values()) {
446+
if (value2.isImpossible())
447+
continue;
444448
if (value1.path != value2.path)
445449
continue;
446450
ValueFlow::Value result;

test/testvalueflow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5026,6 +5026,17 @@ class TestValueFlow : public TestFixture {
50265026
"}\n";
50275027
ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0));
50285028

5029+
code = "bool f(std::string s) {\n"
5030+
" if (!s.empty()) {\n"
5031+
" bool x = s == \"0\";\n"
5032+
" return x;\n"
5033+
" }\n"
5034+
" return false;\n"
5035+
"}\n";
5036+
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 0));
5037+
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
5038+
ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0));
5039+
50295040
code = "std::vector<int> g();\n"
50305041
"int f(bool b) {\n"
50315042
" std::set<int> a;\n"

0 commit comments

Comments
 (0)