From 0523a2125527b6f59ad779bc9710f022043628f9 Mon Sep 17 00:00:00 2001 From: Bobby Battista Date: Tue, 11 Aug 2026 11:19:50 -0400 Subject: [PATCH 1/2] refactor(lib): Add path separator helpers to PathUtil --- Core/Libraries/Include/Lib/PathUtil.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Core/Libraries/Include/Lib/PathUtil.h b/Core/Libraries/Include/Lib/PathUtil.h index cf1ce769d91..eddade82485 100644 --- a/Core/Libraries/Include/Lib/PathUtil.h +++ b/Core/Libraries/Include/Lib/PathUtil.h @@ -23,6 +23,29 @@ #include "BaseType.h" #include +inline char getNativePathSeparator() +{ +#ifdef _WIN32 + return '\\'; +#else + return '/'; +#endif +} + +inline const char* getLastPathSeparator(const char* path) +{ + const char* forward = strrchr(path, '/'); + const char* backward = strrchr(path, '\\'); + return !forward ? backward : (!backward || forward > backward ? forward : backward); +} + +inline const wchar_t* getLastPathSeparator(const wchar_t* path) +{ + const wchar_t* forward = wcsrchr(path, L'/'); + const wchar_t* backward = wcsrchr(path, L'\\'); + return !forward ? backward : (!backward || forward > backward ? forward : backward); +} + inline const char* getExtension(const char* path) { const char* lastDot = strrchr(path, '.'); @@ -32,7 +55,7 @@ inline const char* getExtension(const char* path) return nullptr; } - const char* lastSeparator = maxPtr(strrchr(path, '/'), strrchr(path, '\\')); + const char* lastSeparator = getLastPathSeparator(path); // Check if the dot is contained in the filename if (lastSeparator && lastDot < lastSeparator) @@ -52,7 +75,7 @@ inline const wchar_t* getExtension(const wchar_t* path) return nullptr; } - const wchar_t* lastSeparator = maxPtr(wcsrchr(path, L'/'), wcsrchr(path, L'\\')); + const wchar_t* lastSeparator = getLastPathSeparator(path); // Check if the dot is contained in the filename if (lastSeparator && lastDot < lastSeparator) From 754f164179596bae0e2a5878c4523e55afadfdb8 Mon Sep 17 00:00:00 2001 From: Bobby Battista Date: Tue, 11 Aug 2026 11:21:17 -0400 Subject: [PATCH 2/2] bugfix(map): Guard the fallback map display name against a missing separator --- Core/GameEngine/Source/GameClient/MapUtil.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/GameEngine/Source/GameClient/MapUtil.cpp b/Core/GameEngine/Source/GameClient/MapUtil.cpp index 1806c50741a..8ac297c5804 100644 --- a/Core/GameEngine/Source/GameClient/MapUtil.cpp +++ b/Core/GameEngine/Source/GameClient/MapUtil.cpp @@ -60,12 +60,19 @@ #include "GameLogic/FPUControl.h" #include "GameNetwork/GameInfo.h" #include "GameNetwork/NetworkDefs.h" +#include "Lib/PathUtil.h" //------------------------------------------------------------------------------- // PRIVATE DATA /////////////////////////////////////////////////////////////////////////////////// static const char *mapExtension = ".map"; +static const char *getPathLeaf( const AsciiString &path ) +{ + const char *separator = getLastPathSeparator(path.str()); + return separator ? separator + 1 : path.str(); +} + static Int m_width = 0; ///< Height map width. static Int m_height = 0; ///< Height map height (y size of array). static Int m_borderSize = 0; ///< Non-playable border area. @@ -592,7 +599,7 @@ Bool MapCache::addMap( { // unofficial maps or maps without names AsciiString tempdisplayname; - tempdisplayname = fname.reverseFind('\\') + 1; + tempdisplayname = getPathLeaf(fname); (*this)[lowerFname].m_displayName.translate(tempdisplayname); if (md.m_numPlayers >= 2) { @@ -654,7 +661,7 @@ Bool MapCache::addMap( { DEBUG_LOG(("Missing TheKey_mapName!")); AsciiString tempdisplayname; - tempdisplayname = fname.reverseFind('\\') + 1; + tempdisplayname = getPathLeaf(fname); md.m_displayName.translate(tempdisplayname); if (md.m_numPlayers >= 2) {