From ef27c29f274a69b5420f9bd2177deade5edebde1 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 16 Dec 2023 12:27:26 -0600 Subject: [PATCH] Fix assertion failure in evalSameCondition (#5770) --- lib/programmemory.cpp | 5 +++-- test/testvalueflow.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index cbe4d34c5..91cd0b0b4 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -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 diffConditions1 = setDifference(conditions1, conditions2); std::vector 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()) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 4eac02e21..fcdea7424 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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 b;\n" + " std::vector f;\n" + " if (b == f && h)\n" + " return;\n" + " if (b == f && b == f && c && e < d) {}\n" + "}\n"; + valueOfTok(code, "b"); } void valueFlowUnknownMixedOperators() {