Fix assertion failure in evalSameCondition (#5770)

This commit is contained in:
Paul Fultz II 2023-12-16 12:27:26 -06:00 committed by GitHub
parent 7191ed92b9
commit ef27c29f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -1290,6 +1290,7 @@ namespace {
}))
return false;
std::sort(conditions.begin(), conditions.end(), &TokenExprIdCompare);
conditions.erase(std::unique(conditions.begin(), conditions.end(), &TokenExprIdCompare), conditions.end());
return !conditions.empty() && conditions.front()->exprId() != 0;
}
@ -1357,8 +1358,8 @@ namespace {
return value;
std::vector<const Token*> diffConditions1 = setDifference(conditions1, conditions2);
std::vector<const Token*> diffConditions2 = setDifference(conditions2, conditions1);
pruneConditions(diffConditions1, b, condValues);
pruneConditions(diffConditions2, b, executeAll(diffConditions2));
pruneConditions(diffConditions1, !b, condValues);
pruneConditions(diffConditions2, !b, executeAll(diffConditions2));
if (diffConditions1.size() != diffConditions2.size())
continue;
if (diffConditions1.size() == conditions1.size())

View File

@ -7549,6 +7549,15 @@ private:
" str += s.to_string();\n"
"}\n";
valueOfTok(code, "s");
code = "void a(int e, int d, int c, int h) {\n"
" std::vector<int> b;\n"
" std::vector<int> f;\n"
" if (b == f && h)\n"
" return;\n"
" if (b == f && b == f && c && e < d) {}\n"
"}\n";
valueOfTok(code, "b");
}
void valueFlowUnknownMixedOperators() {