From 756a74bc09e39790b00eddbd0968e62cfdde6bbb Mon Sep 17 00:00:00 2001 From: Bobby Battista Date: Sun, 2 Nov 2025 14:33:02 -0500 Subject: [PATCH 1/4] refactor: Replace manual strrchr implementation with standard function --- Generals/Code/GameEngine/Source/Common/MiniLog.cpp | 11 +++-------- .../GameClient/Drawable/Draw/W3DModelDraw.cpp | 11 +++-------- .../Source/W3DDevice/GameClient/W3DDisplay.cpp | 11 +++-------- Generals/Code/Main/WinMain.cpp | 11 +++-------- Generals/Code/Tools/GUIEdit/Source/WinMain.cpp | 11 +++-------- GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp | 11 +++-------- .../GameClient/Drawable/Draw/W3DModelDraw.cpp | 11 +++-------- .../Source/W3DDevice/GameClient/W3DDisplay.cpp | 11 +++-------- GeneralsMD/Code/Main/WinMain.cpp | 11 +++-------- GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp | 11 +++-------- 10 files changed, 30 insertions(+), 80 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/MiniLog.cpp b/Generals/Code/GameEngine/Source/Common/MiniLog.cpp index eb51834b43..ee2ea310c6 100644 --- a/Generals/Code/GameEngine/Source/Common/MiniLog.cpp +++ b/Generals/Code/GameEngine/Source/Common/MiniLog.cpp @@ -36,15 +36,10 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } // TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet. const std::string fullPath = std::string(buffer) + "\\" + fname; diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index 5f37576fa0..d6241f7588 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -99,15 +99,10 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } // TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet. const std::string fullPath = std::string(buffer) + "\\" + fname; diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index e0ef98d9ae..c84a504c12 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -147,15 +147,10 @@ StatDumpClass::StatDumpClass( const char *fname ) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } // TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet. const std::string fullPath = std::string(buffer) + "\\" + fname; diff --git a/Generals/Code/Main/WinMain.cpp b/Generals/Code/Main/WinMain.cpp index 3eacc83fdf..70f1f7c8d9 100644 --- a/Generals/Code/Main/WinMain.cpp +++ b/Generals/Code/Main/WinMain.cpp @@ -774,15 +774,10 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + Char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } ::SetCurrentDirectory(buffer); diff --git a/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp b/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp index 9cfb49d204..3d9aef33a3 100644 --- a/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp +++ b/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp @@ -187,15 +187,10 @@ Int APIENTRY WinMain(HINSTANCE hInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + Char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } ::SetCurrentDirectory(buffer); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp index 2080dcf278..afb9f25353 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp @@ -36,15 +36,10 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } // TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet. const std::string fullPath = std::string(buffer) + "\\" + fname; diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index ba994253f3..3c9f5193fa 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -99,15 +99,10 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } // TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet. const std::string fullPath = std::string(buffer) + "\\" + fname; diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 61a20797cf..4e75702438 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -148,15 +148,10 @@ StatDumpClass::StatDumpClass( const char *fname ) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } // TheSuperHackers @fix Caball009 03/06/2025 Don't use AsciiString here anymore because its memory allocator may not have been initialized yet. const std::string fullPath = std::string(buffer) + "\\" + fname; diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp index e23d4e4b44..b1cba63590 100644 --- a/GeneralsMD/Code/Main/WinMain.cpp +++ b/GeneralsMD/Code/Main/WinMain.cpp @@ -801,15 +801,10 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + Char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } ::SetCurrentDirectory(buffer); diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp index b6b4375057..83ab162d47 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp @@ -187,15 +187,10 @@ Int APIENTRY WinMain(HINSTANCE hInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = buffer + strlen( buffer ); - while( pEnd != buffer ) + Char *pEnd = strrchr(buffer, '\\'); + if (pEnd != nullptr) { - if( *pEnd == '\\' ) - { - *pEnd = 0; - break; - } - pEnd--; + *pEnd = 0; } ::SetCurrentDirectory(buffer); From 2eda916c632cd8e257a159174a08f29c147a2502 Mon Sep 17 00:00:00 2001 From: Bobby Battista Date: Sun, 2 Nov 2025 14:53:43 -0500 Subject: [PATCH 2/4] fix use NULL instead of null[tr for vc6 --- Generals/Code/GameEngine/Source/Common/MiniLog.cpp | 2 +- .../Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp | 2 +- .../GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | 2 +- Generals/Code/Main/WinMain.cpp | 2 +- Generals/Code/Tools/GUIEdit/Source/WinMain.cpp | 2 +- GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp | 2 +- .../Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp | 2 +- .../GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | 2 +- GeneralsMD/Code/Main/WinMain.cpp | 2 +- GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/MiniLog.cpp b/Generals/Code/GameEngine/Source/Common/MiniLog.cpp index ee2ea310c6..933ee2437f 100644 --- a/Generals/Code/GameEngine/Source/Common/MiniLog.cpp +++ b/Generals/Code/GameEngine/Source/Common/MiniLog.cpp @@ -37,7 +37,7 @@ LogClass::LogClass(const char *fname) char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index d6241f7588..8caccb199c 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -100,7 +100,7 @@ LogClass::LogClass(const char *fname) char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index c84a504c12..3bef5b4214 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -148,7 +148,7 @@ StatDumpClass::StatDumpClass( const char *fname ) char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/Generals/Code/Main/WinMain.cpp b/Generals/Code/Main/WinMain.cpp index 70f1f7c8d9..52ed0e7fe4 100644 --- a/Generals/Code/Main/WinMain.cpp +++ b/Generals/Code/Main/WinMain.cpp @@ -775,7 +775,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp b/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp index 3d9aef33a3..df11d9c39f 100644 --- a/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp +++ b/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp @@ -188,7 +188,7 @@ Int APIENTRY WinMain(HINSTANCE hInstance, Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp index afb9f25353..2c81887439 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp @@ -37,7 +37,7 @@ LogClass::LogClass(const char *fname) char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index 3c9f5193fa..5265f6f879 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -100,7 +100,7 @@ LogClass::LogClass(const char *fname) char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 4e75702438..6137ea0ecc 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -149,7 +149,7 @@ StatDumpClass::StatDumpClass( const char *fname ) char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp index b1cba63590..4b2b87dfde 100644 --- a/GeneralsMD/Code/Main/WinMain.cpp +++ b/GeneralsMD/Code/Main/WinMain.cpp @@ -802,7 +802,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp index 83ab162d47..5177d3c45d 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp @@ -188,7 +188,7 @@ Int APIENTRY WinMain(HINSTANCE hInstance, Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != nullptr) + if (pEnd != NULL) { *pEnd = 0; } From 727502e249714e0ace8f1f65e75bc0be7b36d28d Mon Sep 17 00:00:00 2001 From: Bobby Battista Date: Sun, 2 Nov 2025 16:52:48 -0500 Subject: [PATCH 3/4] refactor: continue refactoring to use strrchr --- .../GameEngine/Source/Common/System/Debug.cpp | 11 +++------- .../Source/Common/System/GameMemoryInit.cpp | 11 +++------- Core/Tools/MapCacheBuilder/Source/WinMain.cpp | 10 +++------ .../Code/Tools/WorldBuilder/src/BuildList.cpp | 11 +++------- .../Tools/WorldBuilder/src/ScriptDialog.cpp | 20 ++++++------------ .../Tools/WorldBuilder/src/WorldBuilder.cpp | 10 +++------ .../WorldBuilder/src/WorldBuilderDoc.cpp | 21 ++++++------------- .../Code/Tools/WorldBuilder/src/BuildList.cpp | 11 +++------- .../Tools/WorldBuilder/src/ScriptDialog.cpp | 20 ++++++------------ .../Tools/WorldBuilder/src/WorldBuilder.cpp | 10 +++------ .../WorldBuilder/src/WorldBuilderDoc.cpp | 21 ++++++------------- 11 files changed, 45 insertions(+), 111 deletions(-) diff --git a/Core/GameEngine/Source/Common/System/Debug.cpp b/Core/GameEngine/Source/Common/System/Debug.cpp index 55dcdcd65f..7973367f80 100644 --- a/Core/GameEngine/Source/Common/System/Debug.cpp +++ b/Core/GameEngine/Source/Common/System/Debug.cpp @@ -376,15 +376,10 @@ void DebugInit(int flags) char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = dirbuf + strlen( dirbuf ); - while( pEnd != dirbuf ) + char *pEnd = strrchr(dirbuf, '\\'); + if (pEnd != NULL) { - if( *pEnd == '\\' ) - { - *(pEnd + 1) = 0; - break; - } - pEnd--; + *(pEnd + 1) = 0; } strcpy(theLogFileNamePrev, dirbuf); diff --git a/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp b/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp index 7a1b0de948..2b4562ddd6 100644 --- a/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp +++ b/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp @@ -113,15 +113,10 @@ void userMemoryManagerInitPools() // we expect. so do it the hard way. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char* pEnd = buf + strlen(buf); - while (pEnd != buf) + char* pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { - if (*pEnd == '\\') - { - *pEnd = 0; - break; - } - --pEnd; + *pEnd = 0; } strlcat(buf, "\\Data\\INI\\MemoryPools.ini", ARRAY_SIZE(buf)); diff --git a/Core/Tools/MapCacheBuilder/Source/WinMain.cpp b/Core/Tools/MapCacheBuilder/Source/WinMain.cpp index 677316fcb7..58cfb0c308 100644 --- a/Core/Tools/MapCacheBuilder/Source/WinMain.cpp +++ b/Core/Tools/MapCacheBuilder/Source/WinMain.cpp @@ -224,13 +224,9 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, // Set the current directory to the app directory. char buf[_MAX_PATH]; GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } ::SetCurrentDirectory(buf); diff --git a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp index a1dcb05cc1..db1728e6b7 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -739,15 +739,10 @@ void BuildList::OnExport() try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = dirbuf + strlen( dirbuf ); - while( pEnd != dirbuf ) + char *pEnd = strrchr(dirbuf, '\\'); + if (pEnd != NULL) { - if( *pEnd == '\\' ) - { - *(pEnd + 1) = 0; - break; - } - pEnd--; + *(pEnd + 1) = 0; } char curbuf[ _MAX_PATH ]; diff --git a/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp b/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp index fb6899d708..f32ac3255f 100644 --- a/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp @@ -1140,13 +1140,9 @@ void ScriptDialog::OnSave() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } ::SetCurrentDirectory(buf); if (IDCANCEL==result) { @@ -1357,13 +1353,9 @@ void ScriptDialog::OnLoad() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); ::SetCurrentDirectory(buf); diff --git a/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp b/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp index 10a160c18a..9ec53d74e1 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp @@ -316,13 +316,9 @@ BOOL CWorldBuilderApp::InitInstance() // Set the current directory to the app directory. char buf[_MAX_PATH]; GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } ::SetCurrentDirectory(buf); diff --git a/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp b/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp index a4364d5f24..ab63b398ad 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp @@ -1359,13 +1359,9 @@ BOOL CWorldBuilderDoc::OnOpenDocument(LPCTSTR lpszPathName) WbApp()->setCurrentDirectory(AsciiString(buf)); ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } ::SetCurrentDirectory(buf); @@ -2105,15 +2101,10 @@ void CWorldBuilderDoc::OnDumpDocToText(void) try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = dirbuf + strlen( dirbuf ); - while( pEnd != dirbuf ) + char *pEnd = strrchr(dirbuf, '\\'); + if (pEnd != NULL) { - if( *pEnd == '\\' ) - { - *(pEnd + 1) = 0; - break; - } - pEnd--; + *(pEnd + 1) = 0; } char curbuf[ _MAX_PATH ]; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp index 0fdd34cb72..25f466b9eb 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -739,15 +739,10 @@ void BuildList::OnExport() try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = dirbuf + strlen( dirbuf ); - while( pEnd != dirbuf ) + char *pEnd = strrchr(dirbuf, '\\'); + if (pEnd != NULL) { - if( *pEnd == '\\' ) - { - *(pEnd + 1) = 0; - break; - } - pEnd--; + *(pEnd + 1) = 0; } char curbuf[ _MAX_PATH ]; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp index 7c02ae3fbe..ffcfa6bdab 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp @@ -1295,13 +1295,9 @@ void ScriptDialog::OnSave() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } ::SetCurrentDirectory(buf); if (IDCANCEL==result) { @@ -1519,13 +1515,9 @@ void ScriptDialog::OnLoad() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); ::SetCurrentDirectory(buf); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp index 2a81f78d5c..2554f0459c 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp @@ -328,13 +328,9 @@ BOOL CWorldBuilderApp::InitInstance() // Set the current directory to the app directory. char buf[_MAX_PATH]; GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } ::SetCurrentDirectory(buf); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp index 52bed9d22c..3f15861bbb 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp @@ -1416,13 +1416,9 @@ BOOL CWorldBuilderDoc::OnOpenDocument(LPCTSTR lpszPathName) WbApp()->setCurrentDirectory(AsciiString(buf)); ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = buf + strlen(buf); - while (pEnd != buf) { - if (*pEnd == '\\') { - *pEnd = 0; - break; - } - pEnd--; + char *pEnd = strrchr(buf, '\\'); + if (pEnd != NULL) { + *pEnd = 0; } ::SetCurrentDirectory(buf); @@ -2162,15 +2158,10 @@ void CWorldBuilderDoc::OnDumpDocToText(void) try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = dirbuf + strlen( dirbuf ); - while( pEnd != dirbuf ) + char *pEnd = strrchr(dirbuf, '\\'); + if (pEnd != NULL) { - if( *pEnd == '\\' ) - { - *(pEnd + 1) = 0; - break; - } - pEnd--; + *(pEnd + 1) = 0; } char curbuf[ _MAX_PATH ]; From a097d5e4d5f5faa0f844139eba6a8ab7af8ff813 Mon Sep 17 00:00:00 2001 From: Bobby Battista Date: Mon, 3 Nov 2025 14:09:44 -0500 Subject: [PATCH 4/4] refactor: Inline strrchr variable declarations --- Core/GameEngine/Source/Common/System/Debug.cpp | 3 +-- Core/GameEngine/Source/Common/System/GameMemoryInit.cpp | 3 +-- Core/Tools/MapCacheBuilder/Source/WinMain.cpp | 3 +-- Generals/Code/GameEngine/Source/Common/MiniLog.cpp | 3 +-- .../W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp | 3 +-- .../Source/W3DDevice/GameClient/W3DDisplay.cpp | 3 +-- Generals/Code/Main/WinMain.cpp | 3 +-- Generals/Code/Tools/GUIEdit/Source/WinMain.cpp | 3 +-- Generals/Code/Tools/WorldBuilder/src/BuildList.cpp | 3 +-- Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp | 6 ++---- Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp | 3 +-- Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp | 6 ++---- GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp | 3 +-- .../W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp | 3 +-- .../Source/W3DDevice/GameClient/W3DDisplay.cpp | 3 +-- GeneralsMD/Code/Main/WinMain.cpp | 3 +-- GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp | 3 +-- GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp | 3 +-- GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp | 6 ++---- GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp | 3 +-- GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp | 6 ++---- 21 files changed, 25 insertions(+), 50 deletions(-) diff --git a/Core/GameEngine/Source/Common/System/Debug.cpp b/Core/GameEngine/Source/Common/System/Debug.cpp index 7973367f80..bb4b885fc4 100644 --- a/Core/GameEngine/Source/Common/System/Debug.cpp +++ b/Core/GameEngine/Source/Common/System/Debug.cpp @@ -376,8 +376,7 @@ void DebugInit(int flags) char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = strrchr(dirbuf, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(dirbuf, '\\')) { *(pEnd + 1) = 0; } diff --git a/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp b/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp index 2b4562ddd6..14eb7762ce 100644 --- a/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp +++ b/Core/GameEngine/Source/Common/System/GameMemoryInit.cpp @@ -113,8 +113,7 @@ void userMemoryManagerInitPools() // we expect. so do it the hard way. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char* pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) + if (char* pEnd = strrchr(buf, '\\')) { *pEnd = 0; } diff --git a/Core/Tools/MapCacheBuilder/Source/WinMain.cpp b/Core/Tools/MapCacheBuilder/Source/WinMain.cpp index 58cfb0c308..9a2d0adca3 100644 --- a/Core/Tools/MapCacheBuilder/Source/WinMain.cpp +++ b/Core/Tools/MapCacheBuilder/Source/WinMain.cpp @@ -224,8 +224,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, // Set the current directory to the app directory. char buf[_MAX_PATH]; GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } ::SetCurrentDirectory(buf); diff --git a/Generals/Code/GameEngine/Source/Common/MiniLog.cpp b/Generals/Code/GameEngine/Source/Common/MiniLog.cpp index 933ee2437f..6d13d9d36e 100644 --- a/Generals/Code/GameEngine/Source/Common/MiniLog.cpp +++ b/Generals/Code/GameEngine/Source/Common/MiniLog.cpp @@ -36,8 +36,7 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index 8caccb199c..f0adfdf007 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -99,8 +99,7 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 3bef5b4214..561f507542 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -147,8 +147,7 @@ StatDumpClass::StatDumpClass( const char *fname ) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/Generals/Code/Main/WinMain.cpp b/Generals/Code/Main/WinMain.cpp index 52ed0e7fe4..303d6da1ce 100644 --- a/Generals/Code/Main/WinMain.cpp +++ b/Generals/Code/Main/WinMain.cpp @@ -774,8 +774,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (Char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp b/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp index df11d9c39f..bc6a055d5e 100644 --- a/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp +++ b/Generals/Code/Tools/GUIEdit/Source/WinMain.cpp @@ -187,8 +187,7 @@ Int APIENTRY WinMain(HINSTANCE hInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (Char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp index db1728e6b7..60b8428399 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -739,8 +739,7 @@ void BuildList::OnExport() try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = strrchr(dirbuf, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(dirbuf, '\\')) { *(pEnd + 1) = 0; } diff --git a/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp b/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp index f32ac3255f..44b8dbad83 100644 --- a/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/ScriptDialog.cpp @@ -1140,8 +1140,7 @@ void ScriptDialog::OnSave() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } ::SetCurrentDirectory(buf); @@ -1353,8 +1352,7 @@ void ScriptDialog::OnLoad() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); diff --git a/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp b/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp index 9ec53d74e1..fa278f7ebe 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp @@ -316,8 +316,7 @@ BOOL CWorldBuilderApp::InitInstance() // Set the current directory to the app directory. char buf[_MAX_PATH]; GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } ::SetCurrentDirectory(buf); diff --git a/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp b/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp index ab63b398ad..b47f959dee 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp @@ -1359,8 +1359,7 @@ BOOL CWorldBuilderDoc::OnOpenDocument(LPCTSTR lpszPathName) WbApp()->setCurrentDirectory(AsciiString(buf)); ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } ::SetCurrentDirectory(buf); @@ -2101,8 +2100,7 @@ void CWorldBuilderDoc::OnDumpDocToText(void) try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = strrchr(dirbuf, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(dirbuf, '\\')) { *(pEnd + 1) = 0; } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp index 2c81887439..034466c45d 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/MiniLog.cpp @@ -36,8 +36,7 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index 5265f6f879..a037733976 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -99,8 +99,7 @@ LogClass::LogClass(const char *fname) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 6137ea0ecc..32a9be834f 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -148,8 +148,7 @@ StatDumpClass::StatDumpClass( const char *fname ) { char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp index 4b2b87dfde..6017276941 100644 --- a/GeneralsMD/Code/Main/WinMain.cpp +++ b/GeneralsMD/Code/Main/WinMain.cpp @@ -801,8 +801,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (Char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp index 5177d3c45d..52ea538ae1 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/WinMain.cpp @@ -187,8 +187,7 @@ Int APIENTRY WinMain(HINSTANCE hInstance, /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); - Char *pEnd = strrchr(buffer, '\\'); - if (pEnd != NULL) + if (Char *pEnd = strrchr(buffer, '\\')) { *pEnd = 0; } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp index 25f466b9eb..3bdd2bc0aa 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -739,8 +739,7 @@ void BuildList::OnExport() try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = strrchr(dirbuf, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(dirbuf, '\\')) { *(pEnd + 1) = 0; } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp index ffcfa6bdab..001fd9c439 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/ScriptDialog.cpp @@ -1295,8 +1295,7 @@ void ScriptDialog::OnSave() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } ::SetCurrentDirectory(buf); @@ -1515,8 +1514,7 @@ void ScriptDialog::OnLoad() // change it back. char buf[_MAX_PATH]; ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp index 2554f0459c..3eaf249a1c 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp @@ -328,8 +328,7 @@ BOOL CWorldBuilderApp::InitInstance() // Set the current directory to the app directory. char buf[_MAX_PATH]; GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } ::SetCurrentDirectory(buf); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp index 3f15861bbb..0dc4175073 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp @@ -1416,8 +1416,7 @@ BOOL CWorldBuilderDoc::OnOpenDocument(LPCTSTR lpszPathName) WbApp()->setCurrentDirectory(AsciiString(buf)); ::GetModuleFileName(NULL, buf, sizeof(buf)); - char *pEnd = strrchr(buf, '\\'); - if (pEnd != NULL) { + if (char *pEnd = strrchr(buf, '\\')) { *pEnd = 0; } ::SetCurrentDirectory(buf); @@ -2158,8 +2157,7 @@ void CWorldBuilderDoc::OnDumpDocToText(void) try { char dirbuf[ _MAX_PATH ]; ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = strrchr(dirbuf, '\\'); - if (pEnd != NULL) + if (char *pEnd = strrchr(dirbuf, '\\')) { *(pEnd + 1) = 0; }