Avoid integer overflow when calculating working set size

PR #16700.
This commit is contained in:
Vladimir Golovnev 2022-03-22 16:15:21 +03:00 committed by GitHub
commit c062f86bac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -798,7 +798,7 @@ void Application::shutdownCleanup(QSessionManager &manager)
#ifdef Q_OS_WIN
void Application::applyMemoryWorkingSetLimit()
{
const int UNIT_SIZE = 1024 * 1024; // MiB
const SIZE_T UNIT_SIZE = 1024 * 1024; // MiB
const SIZE_T maxSize = memoryWorkingSetLimit() * UNIT_SIZE;
const SIZE_T minSize = std::min<SIZE_T>((64 * UNIT_SIZE), (maxSize / 2));
if (!::SetProcessWorkingSetSizeEx(::GetCurrentProcess(), minSize, maxSize, QUOTA_LIMITS_HARDWS_MAX_ENABLE))