From 41bdd87d30fc19d471d9924e58d5d7182597bca4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 18 Aug 2023 21:02:08 +0200 Subject: [PATCH] Fix #11875: hang in hasBorrowingVariables() (#5337) --- lib/valueflow.cpp | 5 ++--- test/testvalueflow.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 8ed4f29cc6c..c873f999edf 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4259,10 +4259,9 @@ struct LifetimeStore { static bool hasBorrowingVariables(const std::list& vars, const std::vector& args, int depth = 10) { if (depth < 0) - return false; + return true; return std::any_of(vars.cbegin(), vars.cend(), [&](const Variable& var) { - const ValueType* vt = var.valueType(); - if (vt) { + if (const ValueType* vt = var.valueType()) { if (vt->pointer > 0 && std::none_of(args.begin(), args.end(), [vt](const Token* arg) { return arg->valueType() && arg->valueType()->type == vt->type; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 50a58464abf..f24942164fa 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7359,6 +7359,17 @@ class TestValueFlow : public TestFixture { " if (llabs(0x80000000ffffffffL) == 0x7fffffff00000001L) {}\n" "}\n"; valueOfTok(code, "f"); + + code = "struct T {\n" + " T();\n" + " static T a[6][64];\n" + " static T b[2][64];\n" + " static T c[64][64];\n" + " static T d[2][64];\n" + " static T e[64];\n" + " static T f[64];\n" + "};\n"; + valueOfTok(code, "("); } void valueFlowCrashConstructorInitialization() { // #9577