From d49cc0b77f058a46eeb23c28237e9787e7d8b1c7 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Wed, 24 May 2023 15:05:05 -0700 Subject: [PATCH] Changed calculation for `threadCount` to prevent unsigned underflow. (#287) * Changed calculation for `threadCount` to prevent unsigned underflow. * Change several things to int32_t. --- src/resource/ResourceManager.cpp | 8 ++++---- src/resource/ResourceManager.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index a0b951401..87f3c3883 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -15,14 +15,14 @@ extern bool SFileCheckWildCard(const char* szString, const char* szWildCard); namespace LUS { ResourceManager::ResourceManager(const std::string& mainPath, const std::string& patchesPath, - const std::unordered_set& validHashes, uint32_t reservedThreadCount) { + const std::unordered_set& validHashes, int32_t reservedThreadCount) { mResourceLoader = std::make_shared(); mArchive = std::make_shared(mainPath, patchesPath, validHashes, false); #if defined(__SWITCH__) || defined(__WIIU__) size_t threadCount = 1; #else // the extra `- 1` is because we reserve an extra thread for spdlog - size_t threadCount = std::max(1U, (std::thread::hardware_concurrency() - reservedThreadCount - 1)); + size_t threadCount = std::max(1, (int32_t)(std::thread::hardware_concurrency() - reservedThreadCount - 1)); #endif mThreadPool = std::make_shared(threadCount); @@ -33,14 +33,14 @@ ResourceManager::ResourceManager(const std::string& mainPath, const std::string& } ResourceManager::ResourceManager(const std::vector& otrFiles, - const std::unordered_set& validHashes, uint32_t reservedThreadCount) { + const std::unordered_set& validHashes, int32_t reservedThreadCount) { mResourceLoader = std::make_shared(); mArchive = std::make_shared(otrFiles, validHashes, false); #if defined(__SWITCH__) || defined(__WIIU__) size_t threadCount = 1; #else // the extra `- 1` is because we reserve an extra thread for spdlog - size_t threadCount = std::max(1U, (std::thread::hardware_concurrency() - reservedThreadCount - 1)); + size_t threadCount = std::max(1, (int32_t)(std::thread::hardware_concurrency() - reservedThreadCount - 1)); #endif mThreadPool = std::make_shared(threadCount); diff --git a/src/resource/ResourceManager.h b/src/resource/ResourceManager.h index dada2b58e..9a7fb7693 100644 --- a/src/resource/ResourceManager.h +++ b/src/resource/ResourceManager.h @@ -22,9 +22,9 @@ class ResourceManager { public: ResourceManager(const std::string& mainPath, const std::string& patchesPath, - const std::unordered_set& validHashes, uint32_t reservedThreadCount = 1); + const std::unordered_set& validHashes, int32_t reservedThreadCount = 1); ResourceManager(const std::vector& otrFiles, const std::unordered_set& validHashes, - uint32_t reservedThreadCount = 1); + int32_t reservedThreadCount = 1); ~ResourceManager(); bool DidLoadSuccessfully();