Fix crash in checkPassByReference() (#4122)

This commit is contained in:
chrchr-github 2022-05-21 16:02:35 +02:00 committed by GitHub
parent 1ed0d9ad92
commit 22a4fdb6c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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());

View File

@ -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"