From d8710c431d88ff59bc73f21bc7c3453ebe460151 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 21 May 2026 18:02:44 +0200 Subject: [PATCH] Fix named_thread_group constructor m_count - 1 could underflow --- Utilities/Thread.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Utilities/Thread.h b/Utilities/Thread.h index bafcea0b9f..66ccfa9fb2 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -797,31 +797,30 @@ public: m_count = 0; // Create all threads - for (u32 i = 0; i < count - 1; i++) + for (; m_count < count - 1; m_count++) { // Copy the context std::remove_cvref_t context(static_cast(f)); // Perform the check and additional preparations for each context - if (!std::invoke(std::forward(check), i, context)) + if (!std::invoke(std::forward(check), m_count, context)) { return; } - m_count++; - new (static_cast(m_threads + i)) Thread(std::string(name) + std::to_string(i + 1), std::move(context)); + new (static_cast(m_threads + m_count)) Thread(std::string(name) + std::to_string(m_count + 1), std::move(context)); } // Move the context (if movable) std::remove_cvref_t context(std::forward(f)); - if (!std::invoke(std::forward(check), m_count - 1, context)) + if (!std::invoke(std::forward(check), m_count, context)) { return; } + new (static_cast(m_threads + m_count)) Thread(std::string(name) + std::to_string(m_count + 1), std::move(context)); m_count++; - new (static_cast(m_threads + m_count - 1)) Thread(std::string(name) + std::to_string(m_count - 1), std::move(context)); } // Default constructor