From 1ac16413ea7225bd37f60903465fb351f7720639 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 22 Feb 2022 00:21:26 -0600 Subject: [PATCH] Another fix for 10800: Hang / memory exhaustion on numerical code (#3851) * Another fix for 10800: Hang / memory exhaustion on numerical code * Format --- lib/valueflow.cpp | 6 ++++++ test/testvalueflow.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9d1e48cf0..0df1cc485 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6874,6 +6874,12 @@ static bool needsInitialization(const Variable* var, bool cpp) static void addToErrorPath(ValueFlow::Value& value, const ValueFlow::Value& from) { std::unordered_set locations; + std::transform(value.errorPath.begin(), + value.errorPath.end(), + std::inserter(locations, locations.begin()), + [](const ErrorPathItem& e) { + return e.first; + }); if (from.condition && !value.condition) value.condition = from.condition; std::copy_if(from.errorPath.begin(), diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 61a5b902d..72498c5d8 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6318,6 +6318,23 @@ private: " d(&f->a, c);\n" "}\n"; valueOfTok(code, "f"); + + code = "struct bo {\n" + " int b, c, a, d;\n" + " char e, g, h, i, aa, j, k, l, m, n, o, p, q, r, t, u, v, w, x, y;\n" + " long z, ab, ac, ad, f, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar,\n" + " as;\n" + " short at, au, av, aw, ax, ay, az, ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk,\n" + " bl, bm;\n" + "};\n" + "char bn;\n" + "void bp() {\n" + " bo s;\n" + " if (bn)\n" + " return;\n" + " s;\n" + "}\n"; + valueOfTok(code, "s"); } void valueFlowHang() {