From 22a4fdb6c4d3b3d724817654b1bb72d084488860 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 21 May 2022 16:02:35 +0200 Subject: [PATCH] Fix crash in checkPassByReference() (#4122) --- lib/checkother.cpp | 2 +- test/testother.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 25cba3ef4..b114b9961 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1178,7 +1178,7 @@ static int estimateSize(const Type* type, const Settings* settings, const Symbol size = settings->sizeof_pointer; else if (var.type() && var.type()->classScope) size = estimateSize(var.type(), settings, symbolDatabase, recursionDepth+1); - else if (var.valueType()->type == ValueType::Type::CONTAINER) + else if (var.valueType() && var.valueType()->type == ValueType::Type::CONTAINER) size = 3 * settings->sizeof_pointer; // Just guess else size = symbolDatabase->sizeOfType(var.typeStartToken()); diff --git a/test/testother.cpp b/test/testother.cpp index a5fef1852..071c683b3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1816,6 +1816,13 @@ private: "void f(S s) {}\n"); ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 's' should be passed by const reference.\n", errout.str()); + check("union U {\n" // don't crash + " int a;\n" + " decltype(nullptr) b;\n" + "};\n" + "int* f(U u) { return u.b; }\n"); + ASSERT_EQUALS("", errout.str()); + Settings settings1; settings1.platform(Settings::Win64); check("using ui64 = unsigned __int64;\n"