diff --git a/src/shared/tree_container.h b/src/shared/tree_container.h index a2f61fa..0282791 100644 --- a/src/shared/tree_container.h +++ b/src/shared/tree_container.h @@ -442,7 +442,7 @@ class TreeContainer } const int count = boost::lexical_cast(match[2]); - return match[1].str() + std::to_string(count + 1); + return std::format("{}{}", match[1].str(), count + 1); } bool unassign(const std::shared_ptr& shm, TreeMeta* tree) diff --git a/src/shared/winapi.cpp b/src/shared/winapi.cpp index e28a13c..64bc1c7 100644 --- a/src/shared/winapi.cpp +++ b/src/shared/winapi.cpp @@ -432,7 +432,8 @@ std::vector quickFindFiles(LPCWSTR directoryName, LPCWSTR pattern) return result; } -bool createPath(boost::filesystem::path path, LPSECURITY_ATTRIBUTES securityAttributes) +bool createPath(const boost::filesystem::path& path, + LPSECURITY_ATTRIBUTES securityAttributes) { // sanity and guaranteed recursion end: if (!path.has_relative_path()) diff --git a/src/shared/winapi.h b/src/shared/winapi.h index f94eff6..e26721c 100644 --- a/src/shared/winapi.h +++ b/src/shared/winapi.h @@ -542,7 +542,7 @@ std::vector quickFindFiles(LPCWSTR directoryName, LPCWSTR pattern); * @return true if the directory (and possibly parent directories) were actually created * and false if the directory already existed. Throws exceptions on failure. */ -bool createPath(boost::filesystem::path path, +bool createPath(const boost::filesystem::path& path, LPSECURITY_ATTRIBUTES securityAttributes = nullptr); inline bool createPath(LPCWSTR path, LPSECURITY_ATTRIBUTES securityAttributes = nullptr) { diff --git a/src/thooklib/ttrampolinepool.cpp b/src/thooklib/ttrampolinepool.cpp index 3b6a51f..1c21954 100644 --- a/src/thooklib/ttrampolinepool.cpp +++ b/src/thooklib/ttrampolinepool.cpp @@ -474,9 +474,11 @@ LPVOID TrampolinePool::currentBufferAddress(LPVOID addressNear) auto lookupAddress = m_Buffers.find(rounded); if (lookupAddress == m_Buffers.end()) { - lookupAddress = m_Buffers.insert(std::make_pair(rounded, BufferList())).first; + lookupAddress = + m_Buffers.try_emplace(rounded /* automatically emplaces default BufferList() */) + .first; } - if (lookupAddress->second.buffers.size() == 0) { + if (lookupAddress->second.buffers.empty()) { allocateBuffer(addressNear); } @@ -503,7 +505,7 @@ TrampolinePool::BufferMap::iterator TrampolinePool::allocateBuffer(LPVOID addres LPVOID rounded = roundAddress(addressNear); auto iter = m_Buffers.find(rounded); uintptr_t lowerEnd = reinterpret_cast(rounded); - if (iter->second.buffers.size() > 0) { + if (!iter->second.buffers.empty()) { // start searching were we last found a buffer lowerEnd = reinterpret_cast(*iter->second.buffers.rbegin()) + sysInfo.dwPageSize; @@ -584,8 +586,7 @@ LPVOID TrampolinePool::releaseInt(LPVOID func) m_ThreadGuards.reset(new TThreadMap()); } - auto iter = m_ThreadGuards->find(func); - if (iter == m_ThreadGuards->end()) { + if (!m_ThreadGuards->contains(func)) { spdlog::get("hooks")->error("failed to release barrier for func {}", func); ::SetLastError(lastError); return nullptr; diff --git a/src/usvfs_dll/hookmanager.cpp b/src/usvfs_dll/hookmanager.cpp index 731b856..d402756 100644 --- a/src/usvfs_dll/hookmanager.cpp +++ b/src/usvfs_dll/hookmanager.cpp @@ -167,8 +167,8 @@ void HookManager::installHook(HMODULE module1, HMODULE module2, spdlog::get("usvfs")->error("failed to hook {0}: {1}", functionName, GetErrorString(err)); } else { - m_Stubs.insert(make_pair(funcAddr, functionName)); - m_Hooks.insert(make_pair(std::string(functionName), handle)); + m_Stubs.try_emplace(funcAddr, functionName); + m_Hooks.try_emplace(std::string(functionName), handle); spdlog::get("usvfs")->info("hooked {0} ({1}) in {2} type {3}", functionName, funcAddr, winapi::ansi::getModuleFileName(usedModule), GetHookType(handle)); @@ -213,8 +213,8 @@ void HookManager::installStub(HMODULE module1, HMODULE module2, spdlog::get("usvfs")->error("failed to stub {0}: {1}", functionName, GetErrorString(err)); } else { - m_Stubs.insert(make_pair(funcAddr, functionName)); - m_Hooks.insert(make_pair(std::string(functionName), handle)); + m_Stubs.try_emplace(funcAddr, functionName); + m_Hooks.try_emplace(std::string(functionName), handle); spdlog::get("usvfs")->info("stubbed {0} ({1}) in {2} type {3}", functionName, funcAddr, winapi::ansi::getModuleFileName(usedModule), GetHookType(handle)); diff --git a/src/usvfs_dll/maptracker.h b/src/usvfs_dll/maptracker.h index ed8daaf..e5836d8 100644 --- a/src/usvfs_dll/maptracker.h +++ b/src/usvfs_dll/maptracker.h @@ -221,7 +221,8 @@ class RerouteW } } - static bool createFakePath(fs::path path, LPSECURITY_ATTRIBUTES securityAttributes) + static bool createFakePath(const fs::path& path, + LPSECURITY_ATTRIBUTES securityAttributes) { // sanity and guaranteed recursion end: if (!path.has_relative_path()) @@ -516,7 +517,7 @@ class RerouteW auto res = create(context, callContext, inPath); if (res.wasRerouted() || !interestingPath(inPath) || !callContext.active() || pathExists(inPath)) - return std::move(res); + return res; } return createNew(context, callContext, inPath, createPath, securityAttributes); } diff --git a/src/usvfs_dll/usvfs.cpp b/src/usvfs_dll/usvfs.cpp index 56d9f71..8f042c8 100644 --- a/src/usvfs_dll/usvfs.cpp +++ b/src/usvfs_dll/usvfs.cpp @@ -418,7 +418,7 @@ void __cdecl InitHooks(LPVOID parameters, size_t) auto context = manager->context(); auto exePath = boost::dll::program_location(); auto libraries = context->librariesToForceLoad(exePath.filename().c_str()); - for (auto library : libraries) { + for (const auto& library : libraries) { if (std::filesystem::exists(library)) { const auto ret = LoadLibraryExW(library.c_str(), NULL, 0); if (ret) { @@ -588,9 +588,9 @@ bool assertPathExists(usvfs::RedirectionTreeContainer& table, LPCWSTR path) usvfs::RedirectionTree::NodeT* current = table.get(); for (auto iter = p.begin(); iter != p.end(); iter = ush::nextIter(iter, p.end())) { - if (current->exists(iter->string().c_str())) { + if (current->exists(iter->string())) { // subdirectory exists virtually, all good - usvfs::RedirectionTree::NodePtrT found = current->node(iter->string().c_str()); + usvfs::RedirectionTree::NodePtrT found = current->node(iter->string()); current = found.get().get(); } else { // targetPath is relative to the last rerouted "real" path. This means