Skip to content

Commit ef27c29

Browse files
authored
Fix assertion failure in evalSameCondition (danmar#5770)
1 parent 7191ed9 commit ef27c29

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/programmemory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ namespace {
12901290
}))
12911291
return false;
12921292
std::sort(conditions.begin(), conditions.end(), &TokenExprIdCompare);
1293+
conditions.erase(std::unique(conditions.begin(), conditions.end(), &TokenExprIdCompare), conditions.end());
12931294
return !conditions.empty() && conditions.front()->exprId() != 0;
12941295
}
12951296

@@ -1357,8 +1358,8 @@ namespace {
13571358
return value;
13581359
std::vector<const Token*> diffConditions1 = setDifference(conditions1, conditions2);
13591360
std::vector<const Token*> diffConditions2 = setDifference(conditions2, conditions1);
1360-
pruneConditions(diffConditions1, b, condValues);
1361-
pruneConditions(diffConditions2, b, executeAll(diffConditions2));
1361+
pruneConditions(diffConditions1, !b, condValues);
1362+
pruneConditions(diffConditions2, !b, executeAll(diffConditions2));
13621363
if (diffConditions1.size() != diffConditions2.size())
13631364
continue;
13641365
if (diffConditions1.size() == conditions1.size())

test/testvalueflow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7549,6 +7549,15 @@ class TestValueFlow : public TestFixture {
75497549
" str += s.to_string();\n"
75507550
"}\n";
75517551
valueOfTok(code, "s");
7552+
7553+
code = "void a(int e, int d, int c, int h) {\n"
7554+
" std::vector<int> b;\n"
7555+
" std::vector<int> f;\n"
7556+
" if (b == f && h)\n"
7557+
" return;\n"
7558+
" if (b == f && b == f && c && e < d) {}\n"
7559+
"}\n";
7560+
valueOfTok(code, "b");
75527561
}
75537562

75547563
void valueFlowUnknownMixedOperators() {

0 commit comments

Comments
 (0)