From d731e0112ed6834052030d7ce61b24fb404d2f4e Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 29 Mar 2026 19:43:46 -0700 Subject: [PATCH] fix: std::tolower(char) UB on signed char at 3 call sites std::tolower(int) has undefined behavior when passed a negative value, which signed char produces for bytes > 127. The rest of the codebase correctly casts to unsigned char first; these 3 sites were missed. --- src/core/application.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/application.cpp b/src/core/application.cpp index 579aa38d..3557cdfa 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -4838,7 +4838,7 @@ void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float if (basePath.size() > 4) { extension = basePath.substr(basePath.size() - 4); std::string extLower = extension; - for (char& c : extLower) c = std::tolower(c); + for (char& c : extLower) c = static_cast(std::tolower(static_cast(c))); if (extLower == ".wmo") { basePath = basePath.substr(0, basePath.size() - 4); } @@ -4949,7 +4949,7 @@ void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float if (m2Path.size() > 4) { std::string ext = m2Path.substr(m2Path.size() - 4); - for (char& c : ext) c = std::tolower(c); + for (char& c : ext) c = static_cast(std::tolower(static_cast(c))); if (ext == ".mdx" || ext == ".mdl") { m2Path = m2Path.substr(0, m2Path.size() - 4) + ".m2"; } @@ -5789,7 +5789,7 @@ void Application::buildGameObjectDisplayLookups() { if (modelName.empty()) continue; if (modelName.size() >= 4) { std::string ext = modelName.substr(modelName.size() - 4); - for (char& c : ext) c = static_cast(std::tolower(c)); + for (char& c : ext) c = static_cast(std::tolower(static_cast(c))); if (ext == ".mdx") { modelName = modelName.substr(0, modelName.size() - 4) + ".m2"; }