From fb06e399dac98b88c94feb21037f90533720ce3e Mon Sep 17 00:00:00 2001 From: Bruno Da Silva Date: Wed, 22 Apr 2026 22:33:35 +0000 Subject: [PATCH 1/4] fix: legit bugs found by compiler warnings --- AI/Wrappers/CUtils/SimpleLog.c | 3 ++- rts/Game/InMapDrawModel.cpp | 2 +- rts/Game/UnsyncedGameCommands.cpp | 2 +- rts/Lua/LuaFonts.cpp | 4 +--- rts/Lua/LuaOpenGL.cpp | 6 +++--- rts/Rendering/Fonts/CFontTexture.cpp | 2 +- rts/Rendering/GL/FBO.h | 6 +++--- rts/Rendering/Models/3DModelPiece.hpp | 1 + rts/Rml/SolLua/RmlSolLua.cpp | 2 +- rts/System/Platform/Linux/CpuTopology.cpp | 4 ++-- rts/System/Platform/Watchdog.cpp | 22 ++++++++++++++++++---- 11 files changed, 34 insertions(+), 20 deletions(-) diff --git a/AI/Wrappers/CUtils/SimpleLog.c b/AI/Wrappers/CUtils/SimpleLog.c index c239c337049..da7b8e762fb 100644 --- a/AI/Wrappers/CUtils/SimpleLog.c +++ b/AI/Wrappers/CUtils/SimpleLog.c @@ -95,7 +95,8 @@ void simpleLog_log(const char* fmt, ...) { void simpleLog_initcallback(int id, const char* section, logfunction func, int _logLevel) { - strncpy(logSection, section, 32); + strncpy(logSection, section, sizeof(logSection) - 1); + logSection[sizeof(logSection) - 1] = '\0'; logFunction = func; interfaceid = id; logLevel = _logLevel; diff --git a/rts/Game/InMapDrawModel.cpp b/rts/Game/InMapDrawModel.cpp index d2916ad4832..08d87f9f1b5 100644 --- a/rts/Game/InMapDrawModel.cpp +++ b/rts/Game/InMapDrawModel.cpp @@ -145,7 +145,7 @@ void CInMapDrawModel::EraseNear(const float3& constPos, int playerID, const bool if (!playerHandler.IsValidPlayer(playerID)) return; - const CPlayer* sender; + const CPlayer* sender = nullptr; if (!alwaysErase) // we don't need to check sender if we always erase regardless of sender sender = playerHandler.Player(playerID); diff --git a/rts/Game/UnsyncedGameCommands.cpp b/rts/Game/UnsyncedGameCommands.cpp index 48f7ee76aae..d5b80f5f44f 100644 --- a/rts/Game/UnsyncedGameCommands.cpp +++ b/rts/Game/UnsyncedGameCommands.cpp @@ -270,7 +270,7 @@ class MapMeshDrawerActionExecutor : public IUnsyncedActionExecutor { } auto args = CSimpleParser::Tokenize(action.GetArgs()); - bool parseFailure; + bool parseFailure = false; int smfMeshDrawerArg = (!args.empty()) ? StringToInt(args[0], &parseFailure) : -1.0; if (parseFailure) smfMeshDrawerArg = -1.0; diff --git a/rts/Lua/LuaFonts.cpp b/rts/Lua/LuaFonts.cpp index 34d53693f75..05a0b3d0f55 100644 --- a/rts/Lua/LuaFonts.cpp +++ b/rts/Lua/LuaFonts.cpp @@ -200,9 +200,7 @@ int LuaFonts::LoadFont(lua_State* L) return 0; auto shPtrFontPtr = static_cast(lua_newuserdata(L, sizeof(decltype(f)))); - memset(shPtrFontPtr, 0, sizeof(decltype(f))); - - *shPtrFontPtr = std::move(f); + new (shPtrFontPtr) decltype(f)(std::move(f)); luaL_getmetatable(L, "Font"); lua_setmetatable(L, -2); diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index 479c9a7aed3..d2f0103c8cc 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -2922,9 +2922,9 @@ int LuaOpenGL::DispatchCompute(lua_State* L) static std::array maxNumGroups = maxCompWGFunc(); - if (numGroupX < 0 && numGroupX > maxNumGroups[0] || - numGroupY < 0 && numGroupY > maxNumGroups[1] || - numGroupZ < 0 && numGroupZ > maxNumGroups[2]) + if (numGroupX < 0 || numGroupX > maxNumGroups[0] || + numGroupY < 0 || numGroupY > maxNumGroups[1] || + numGroupZ < 0 || numGroupZ > maxNumGroups[2]) luaL_error(L, "%s Incorrect number of work groups specified x: 0 > %d < %d; y: 0 > %d < %d; z: 0 > %d < %d", __func__, numGroupX, maxNumGroups[0], numGroupY, maxNumGroups[1], numGroupZ, maxNumGroups[2]); glDispatchCompute(numGroupX, numGroupY, numGroupZ); diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index e4ee33c5f95..24639a82d99 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -924,7 +924,7 @@ void CFontTexture::PinFont(std::shared_ptr& face, const std::string& f cached->second.timestamp = time; } else { if (pinnedRecentFonts.size() >= maxPinnedFonts) { - SizedFontKey* oldest; + SizedFontKey* oldest = nullptr; float oldestTime = time; for(auto &[key, timestampedFont]: pinnedRecentFonts) { if (timestampedFont.timestamp <= oldestTime) { diff --git a/rts/Rendering/GL/FBO.h b/rts/Rendering/GL/FBO.h index 76bb809e20e..10f5f121789 100644 --- a/rts/Rendering/GL/FBO.h +++ b/rts/Rendering/GL/FBO.h @@ -188,9 +188,9 @@ class FBO } public: - GLuint id; - GLsizei xsize, ysize, zsize; - GLenum target, format, type; + GLuint id = 0; + GLsizei xsize = 0, ysize = 0, zsize = 0; + GLenum target = 0, format = 0, type = 0; std::vector pixels; }; diff --git a/rts/Rendering/Models/3DModelPiece.hpp b/rts/Rendering/Models/3DModelPiece.hpp index e7e7c0f093b..40675d0f8ff 100644 --- a/rts/Rendering/Models/3DModelPiece.hpp +++ b/rts/Rendering/Models/3DModelPiece.hpp @@ -15,6 +15,7 @@ struct S3DModel; struct S3DModelPiece { S3DModelPiece() = default; + virtual ~S3DModelPiece() = default; virtual void Clear() { name.clear(); diff --git a/rts/Rml/SolLua/RmlSolLua.cpp b/rts/Rml/SolLua/RmlSolLua.cpp index 3545a678b98..ded77cc4a0c 100644 --- a/rts/Rml/SolLua/RmlSolLua.cpp +++ b/rts/Rml/SolLua/RmlSolLua.cpp @@ -41,7 +41,7 @@ namespace Rml::SolLua { SolLuaPlugin* Initialise(sol::state_view* state, const Rml::String& lua_environment_identifier) { - SolLuaPlugin* slp; + SolLuaPlugin* slp = nullptr; if (state != nullptr) { slp = new SolLuaPlugin(*state, lua_environment_identifier); diff --git a/rts/System/Platform/Linux/CpuTopology.cpp b/rts/System/Platform/Linux/CpuTopology.cpp index d6f44053827..8088b94a7f4 100644 --- a/rts/System/Platform/Linux/CpuTopology.cpp +++ b/rts/System/Platform/Linux/CpuTopology.cpp @@ -142,7 +142,7 @@ enum Vendor { VENDOR_INTEL, VENDOR_AMD, VENDOR_UNKNOWN }; // Detect CPU vendor (Intel or VENDOR_AMD) Vendor detect_cpu_vendor() { - unsigned int eax, ebx, ecx, edx; + unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; __get_cpuid(0, &eax, &ebx, &ecx, &edx); if (ebx == 0x756E6547) return VENDOR_INTEL; // "GenuineIntel" if (ebx == 0x68747541) return VENDOR_AMD; // "AuthenticAMD" @@ -152,7 +152,7 @@ Vendor detect_cpu_vendor() { // Detect Intel core type using CPUID 0x1A CoreType get_intel_core_type(int cpu) { set_cpu_affinity(cpu); - unsigned int eax, ebx, ecx, edx; + unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; if (__get_cpuid(0x1A, &eax, &ebx, &ecx, &edx)) { uint8_t coreType = ( eax & 0xFF000000 ) >> 24; // Extract core type diff --git a/rts/System/Platform/Watchdog.cpp b/rts/System/Platform/Watchdog.cpp index 050822380fe..a1248fe4409 100644 --- a/rts/System/Platform/Watchdog.cpp +++ b/rts/System/Platform/Watchdog.cpp @@ -366,12 +366,19 @@ namespace Watchdog { std::lock_guard lock(wdmutex); - memset(registeredThreadsData, 0, sizeof(registeredThreadsData)); + for (auto& info : registeredThreadsData) { + info.ResetThreadInfo(); + info.ResetThreadControls(); + } for (unsigned int i = 0; i < WDT_COUNT; ++i) { registeredThreads[i] = ®isteredThreadsData[WDT_COUNT]; threadNumTable[hashString(threadNames[i])] = i; } - memset(threadSlots, 0, sizeof(threadSlots)); + for (auto& slot : threadSlots) { + slot.primary = false; + slot.active = false; + slot.regorder = 0; + } // disable if gdb is running if (Platform::IsRunningInDebugger()) { @@ -416,10 +423,17 @@ namespace Watchdog hangDetectorThread.join(); LOG_L(L_INFO, "[WatchDog::%s][3]", __func__); - memset(registeredThreadsData, 0, sizeof(registeredThreadsData)); + for (auto& info : registeredThreadsData) { + info.ResetThreadInfo(); + info.ResetThreadControls(); + } for (unsigned int i = 0; i < WDT_COUNT; ++i) registeredThreads[i] = ®isteredThreadsData[WDT_COUNT]; - memset(threadSlots, 0, sizeof(threadSlots)); + for (auto& slot : threadSlots) { + slot.primary = false; + slot.active = false; + slot.regorder = 0; + } threadNumTable.clear(); } } From 37fd636bf462d66861183988d7725da9b0a743e5 Mon Sep 17 00:00:00 2001 From: Bruno Da Silva Date: Fri, 24 Apr 2026 04:08:44 +0000 Subject: [PATCH 2/4] fix for nullptr dereference --- rts/Rendering/Fonts/CFontTexture.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rts/Rendering/Fonts/CFontTexture.cpp b/rts/Rendering/Fonts/CFontTexture.cpp index 24639a82d99..3c6ac3660e0 100644 --- a/rts/Rendering/Fonts/CFontTexture.cpp +++ b/rts/Rendering/Fonts/CFontTexture.cpp @@ -932,7 +932,9 @@ void CFontTexture::PinFont(std::shared_ptr& face, const std::string& f oldestTime = timestampedFont.timestamp; } } - pinnedRecentFonts.erase(*oldest); + if (oldest != nullptr) { + pinnedRecentFonts.erase(*oldest); + } } pinnedRecentFonts[fontKey] = { face, time }; } From d0cec197a6109b435d848bf2f29cff4b3c5e3ba9 Mon Sep 17 00:00:00 2001 From: Bruno Da Silva Date: Fri, 24 Apr 2026 04:28:28 +0000 Subject: [PATCH 3/4] zero check on unsigned int, update error string --- rts/Lua/LuaOpenGL.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index d2f0103c8cc..1a6bb23e4e3 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -2922,10 +2922,10 @@ int LuaOpenGL::DispatchCompute(lua_State* L) static std::array maxNumGroups = maxCompWGFunc(); - if (numGroupX < 0 || numGroupX > maxNumGroups[0] || - numGroupY < 0 || numGroupY > maxNumGroups[1] || - numGroupZ < 0 || numGroupZ > maxNumGroups[2]) - luaL_error(L, "%s Incorrect number of work groups specified x: 0 > %d < %d; y: 0 > %d < %d; z: 0 > %d < %d", __func__, numGroupX, maxNumGroups[0], numGroupY, maxNumGroups[1], numGroupZ, maxNumGroups[2]); + if (numGroupX > maxNumGroups[0] || + numGroupY > maxNumGroups[1] || + numGroupZ > maxNumGroups[2]) + luaL_error(L, "%s: work groups count exceeds GL_MAX_COMPUTE_WORK_GROUP_COUNT. (x=%u > %d, y=%u > %d, z=%u > %d)", __func__, numGroupX, maxNumGroups[0], numGroupY, maxNumGroups[1], numGroupZ, maxNumGroups[2]); glDispatchCompute(numGroupX, numGroupY, numGroupZ); From f20cefb579564937238bbf4bf13b1962cc6ce900 Mon Sep 17 00:00:00 2001 From: Bruno Da Silva Date: Mon, 1 Jun 2026 12:13:17 +0000 Subject: [PATCH 4/4] add a Reset() into WatchDogThreadSlot --- rts/System/Platform/Watchdog.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rts/System/Platform/Watchdog.cpp b/rts/System/Platform/Watchdog.cpp index a1248fe4409..39a794f899a 100644 --- a/rts/System/Platform/Watchdog.cpp +++ b/rts/System/Platform/Watchdog.cpp @@ -66,6 +66,12 @@ namespace Watchdog }; struct WatchDogThreadSlot { + void Reset() { + primary = false; + active = false; + regorder = 0; + } + std::atomic primary = {false}; std::atomic active = {false}; std::atomic regorder = {0}; @@ -374,11 +380,8 @@ namespace Watchdog registeredThreads[i] = ®isteredThreadsData[WDT_COUNT]; threadNumTable[hashString(threadNames[i])] = i; } - for (auto& slot : threadSlots) { - slot.primary = false; - slot.active = false; - slot.regorder = 0; - } + for (auto& slot : threadSlots) + slot.Reset(); // disable if gdb is running if (Platform::IsRunningInDebugger()) { @@ -429,11 +432,8 @@ namespace Watchdog } for (unsigned int i = 0; i < WDT_COUNT; ++i) registeredThreads[i] = ®isteredThreadsData[WDT_COUNT]; - for (auto& slot : threadSlots) { - slot.primary = false; - slot.active = false; - slot.regorder = 0; - } + for (auto& slot : threadSlots) + slot.Reset(); threadNumTable.clear(); } }