From 08ee57b0e356a96a48cbdcada564357bdeacc6a4 Mon Sep 17 00:00:00 2001 From: Bart Roossien Date: Thu, 4 Sep 2025 09:19:51 +0200 Subject: [PATCH 1/5] refactor: Replacing strncpy with strlcpy --- .../Libraries/Source/WWVegas/WW3D2/collect.cpp | 2 +- Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp | 2 +- .../Libraries/Source/WWVegas/WW3D2/hmdldef.cpp | 6 ++---- .../Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp | 4 ++-- .../Source/WWVegas/WWDownload/Download.cpp | 18 +++++++++--------- .../Source/WWVegas/WWDownload/FTP.CPP | 11 ++++++----- Core/Libraries/Source/WWVegas/WWLib/TARGA.CPP | 4 ++-- .../Source/WWVegas/WWLib/cpudetect.cpp | 2 +- Core/Libraries/Source/WWVegas/WWLib/ini.cpp | 6 ++---- Core/Libraries/Source/debug/CMakeLists.txt | 1 + Core/Libraries/Source/debug/debug_debug.cpp | 10 +++++----- Core/Libraries/Source/debug/debug_io_flat.cpp | 11 ++++------- Core/Libraries/Source/debug/debug_stack.cpp | 10 ++++------ Core/Libraries/Source/profile/CMakeLists.txt | 1 + .../Source/profile/profile_highlevel.cpp | 4 ++-- Core/Tools/ImagePacker/Source/ImagePacker.cpp | 4 ++-- .../Code/GameEngine/Source/Common/Recorder.cpp | 2 +- .../Source/Common/Thing/ThingTemplate.cpp | 2 +- .../GUICallbacks/Menus/WOLQuickMatchMenu.cpp | 3 +-- .../GameEngine/Source/GameClient/MapUtil.cpp | 6 ++---- .../GameNetwork/GameSpy/Thread/BuddyThread.cpp | 3 +-- .../GameEngine/Source/GameNetwork/LANAPI.cpp | 13 +++++-------- .../Source/GameNetwork/LANAPIhandlers.cpp | 4 ++-- .../GameClient/Shadow/W3DProjectedShadow.cpp | 12 ++++++------ .../GameClient/Shadow/W3DVolumetricShadow.cpp | 4 ++-- .../W3DDevice/GameClient/W3DFileSystem.cpp | 2 +- .../W3DDevice/GameLogic/W3DTerrainLogic.cpp | 3 +-- .../Libraries/Source/WWVegas/WW3D2/ddsfile.cpp | 2 +- .../Source/WWVegas/WW3D2/dx8wrapper.cpp | 3 +-- .../Libraries/Source/WWVegas/WW3D2/hlod.cpp | 2 +- .../Source/WWVegas/WW3D2/hmorphanim.cpp | 12 +++++------- .../Source/WWVegas/WW3D2/hrawanim.cpp | 2 +- .../Source/WWVegas/WW3D2/meshmdlio.cpp | 4 ++-- .../Tools/WorldBuilder/src/BlendMaterial.cpp | 2 +- .../Tools/WorldBuilder/src/TerrainMaterial.cpp | 2 +- .../Tools/WorldBuilder/src/TerrainModal.cpp | 2 +- .../Code/GameEngine/Source/Common/Recorder.cpp | 2 +- .../Source/Common/Thing/ThingTemplate.cpp | 2 +- .../GUICallbacks/Menus/WOLQuickMatchMenu.cpp | 3 +-- .../GameEngine/Source/GameClient/MapUtil.cpp | 6 ++---- .../GameNetwork/GameSpy/Thread/BuddyThread.cpp | 3 +-- .../GameEngine/Source/GameNetwork/LANAPI.cpp | 14 +++++--------- .../Source/GameNetwork/LANAPIhandlers.cpp | 4 ++-- .../GameClient/Shadow/W3DProjectedShadow.cpp | 12 ++++++------ .../GameClient/Shadow/W3DVolumetricShadow.cpp | 4 ++-- .../W3DDevice/GameClient/W3DFileSystem.cpp | 2 +- .../W3DDevice/GameLogic/W3DTerrainLogic.cpp | 3 +-- .../Libraries/Source/WWVegas/WW3D2/ddsfile.cpp | 2 +- .../Source/WWVegas/WW3D2/dx8wrapper.cpp | 3 +-- .../Libraries/Source/WWVegas/WW3D2/hlod.cpp | 2 +- .../Source/WWVegas/WW3D2/hmorphanim.cpp | 12 +++++------- .../Source/WWVegas/WW3D2/hrawanim.cpp | 2 +- .../Source/WWVegas/WW3D2/meshmdlio.cpp | 4 ++-- .../Tools/WorldBuilder/src/BlendMaterial.cpp | 2 +- .../Code/Tools/WorldBuilder/src/EditAction.cpp | 6 ++---- .../Tools/WorldBuilder/src/EditCondition.cpp | 6 ++---- .../Tools/WorldBuilder/src/TerrainMaterial.cpp | 2 +- .../Tools/WorldBuilder/src/TerrainModal.cpp | 2 +- 58 files changed, 123 insertions(+), 156 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/collect.cpp b/Core/Libraries/Source/WWVegas/WW3D2/collect.cpp index c911d68dd2..eaefe47fbd 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/collect.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/collect.cpp @@ -1015,7 +1015,7 @@ WW3DErrorType CollectionDefClass::Load(ChunkLoadClass & cload) if (cload.Read(&header,sizeof(header)) != sizeof(header)) goto Error; if (!cload.Close_Chunk()) goto Error; - strncpy(Name,header.Name,W3D_NAME_LEN); + strlcpy(Name,header.Name,W3D_NAME_LEN); ObjectNames.Resize(header.RenderObjectCount); while (cload.Open_Chunk()) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp b/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp index b6ff212482..0136f44882 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp @@ -264,7 +264,7 @@ int HCompressedAnimClass::Load_W3D(ChunkLoadClass & cload) WWASSERT(HierarchyName != NULL); WWASSERT(aheader.HierarchyName != NULL); WWASSERT(sizeof(HierarchyName) >= W3D_NAME_LEN); - strncpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); + strlcpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName); if (base_pose == NULL) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp b/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp index 54932d0489..352e56d35b 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp @@ -149,10 +149,8 @@ int HModelDefClass::Load_W3D(ChunkLoadClass & cload) /* ** process the header info */ - strncpy(ModelName,header.Name,W3D_NAME_LEN); - ModelName[W3D_NAME_LEN - 1] = 0; - strncpy(BasePoseName,header.HierarchyName,W3D_NAME_LEN); - BasePoseName[W3D_NAME_LEN-1] = 0; + strlcpy(ModelName,header.Name,W3D_NAME_LEN); + strlcpy(BasePoseName,header.HierarchyName,W3D_NAME_LEN); strcpy(Name,ModelName); /* diff --git a/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp b/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp index 49279e03ce..38c7e8a3e0 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp @@ -532,9 +532,9 @@ static void Get_W3D_Name (const char *filename, char *w3d_name) // Copy all characters from start to end (excluding 'end') // into the w3d_name buffer. Then capitalize the string. - memset(w3d_name, 0, W3D_NAME_LEN); // blank out the buffer int num_chars = end - start; - strncpy(w3d_name, start, num_chars < W3D_NAME_LEN ? num_chars : W3D_NAME_LEN-1); + WWASSERT(num_chars <= W3D_NAME_LEN); + strlcpy(w3d_name, start, min(W3D_NAME_LEN, num_chars)); strupr(w3d_name); } diff --git a/Core/Libraries/Source/WWVegas/WWDownload/Download.cpp b/Core/Libraries/Source/WWVegas/WWDownload/Download.cpp index 05e5dbb3ed..803bbdc84a 100644 --- a/Core/Libraries/Source/WWVegas/WWDownload/Download.cpp +++ b/Core/Libraries/Source/WWVegas/WWDownload/Download.cpp @@ -19,6 +19,7 @@ // Download.cpp : Implementation of CDownload #include "DownloadDebug.h" #include "Download.h" +#include "stringex.h" #include #include #include @@ -69,15 +70,15 @@ HRESULT CDownload::DownloadFile(LPCSTR server, LPCSTR username, LPCSTR password, _mkdir("download"); // Copy parameters to member variables. - strncpy( m_Server, server, sizeof( m_Server ) ); - strncpy( m_Login, username, sizeof( m_Login ) ); - strncpy( m_Password, password, sizeof( m_Password ) ); - strncpy( m_File, file, sizeof( m_File ) ); - strncpy( m_LocalFile, localfile, sizeof( m_LocalFile ) ); + strlcpy( m_Server, server, sizeof( m_Server ) ); + strlcpy( m_Login, username, sizeof( m_Login ) ); + strlcpy( m_Password, password, sizeof( m_Password ) ); + strlcpy( m_File, file, sizeof( m_File ) ); + strlcpy( m_LocalFile, localfile, sizeof( m_LocalFile ) ); - strncpy( m_LastLocalFile, localfile, sizeof( m_LastLocalFile ) ); + strlcpy( m_LastLocalFile, localfile, sizeof( m_LastLocalFile ) ); - strncpy( m_RegKey, regkey, sizeof( m_RegKey ) ); + strlcpy( m_RegKey, regkey, sizeof( m_RegKey ) ); m_TryResume = tryresume; m_StartPosition=0; @@ -113,8 +114,7 @@ HRESULT CDownload::GetLastLocalFile(char *local_file, int maxlen) { if (local_file==0) return(E_FAIL); - strncpy(local_file, m_LastLocalFile, maxlen); - local_file[maxlen-1]=0; + strlcpy(local_file, m_LastLocalFile, maxlen); return(S_OK); } diff --git a/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP b/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP index f4e807c5bd..12b4c520bd 100644 --- a/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP +++ b/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP @@ -38,6 +38,7 @@ #include //#include "wlib/wstring.h" +#include "stringex.h" #include "DownloadDebug.h" // umm... what?? BGC 3/27/03 @@ -324,7 +325,7 @@ HRESULT Cftp::ConnectToServer(LPCSTR szServerName) char buffer[ 256 ]; int iReply, error; - strncpy( m_szServerName, szServerName, 128 ); + strlcpy( m_szServerName, szServerName, sizeof(m_szServerName)); if( m_iStatus == FTPSTAT_INIT ) { @@ -487,8 +488,8 @@ HRESULT Cftp::LoginToServer( LPCSTR szUserName, LPCSTR szPassword ) char command[ 256 ]; int iReply; - strncpy( m_szUserName, szUserName, 128 ); - strncpy( m_szPassword, szPassword, 128 ); + strlcpy( m_szUserName, szUserName, sizeof(m_szUserName)); + strlcpy( m_szPassword, szPassword, sizeof(m_szPassword)); memset( command, 0, 256 ); @@ -1396,7 +1397,7 @@ HRESULT Cftp::GetNextFileBlock( LPCSTR szLocalFileName, int * piTotalRead ) //char str[ 256 ]; - strncpy( m_szLocalFileName, szLocalFileName, 256 ); + strlcpy( m_szLocalFileName, szLocalFileName, sizeof(m_szLocalFileName)); // Open local file @@ -1831,7 +1832,7 @@ bool Prepare_Directories(const char *rootdir, const char *filename) while(cptr=strchr(cptr,'\\')) { memset(tempstr,0,256); - strncpy(tempstr,filename,cptr-filename); + strlcpy(tempstr,filename,cptr-filename); sprintf(newdir,"%s\\%s",rootdir, tempstr); if (!CreateDirectory(newdir, NULL)) return false; diff --git a/Core/Libraries/Source/WWVegas/WWLib/TARGA.CPP b/Core/Libraries/Source/WWVegas/WWLib/TARGA.CPP index c4a027ed8f..d05c50ea87 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/TARGA.CPP +++ b/Core/Libraries/Source/WWVegas/WWLib/TARGA.CPP @@ -713,7 +713,7 @@ long Targa::Save(const char* name, long flags, bool addextension) if (!error) { mExtension.ExtSize = 495; - strncpy(mExtension.SoftID, "Denzil's Targa Code", 41); + strlcpy(mExtension.SoftID, "Denzil's Targa Code", sizeof(mExtension.SoftID)); mExtension.SoftVer.Number = (1 * 100); mExtension.SoftVer.Letter = 0; @@ -735,7 +735,7 @@ long Targa::Save(const char* name, long flags, bool addextension) if (!error) { footer.Developer = 0; - strncpy(footer.Signature, TGA2_SIGNATURE, 16); + strlcpy(footer.Signature, TGA2_SIGNATURE, sizeof(footer.Signature)); footer.RsvdChar = '.'; footer.BZST = 0; diff --git a/Core/Libraries/Source/WWVegas/WWLib/cpudetect.cpp b/Core/Libraries/Source/WWVegas/WWLib/cpudetect.cpp index b972a50ec7..e08182ff2a 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/cpudetect.cpp +++ b/Core/Libraries/Source/WWVegas/WWLib/cpudetect.cpp @@ -802,7 +802,7 @@ void CPUDetectClass::Init_Processor_String() case INTEL_PROCESSOR_PENTIUM4: str+="Pentium4"; break; } } - strncpy(ProcessorString,str.str(),sizeof(ProcessorString)); + strlcpy(ProcessorString,str.str(),sizeof(ProcessorString)); } } diff --git a/Core/Libraries/Source/WWVegas/WWLib/ini.cpp b/Core/Libraries/Source/WWVegas/WWLib/ini.cpp index 82b0f0b549..1cc1a5a279 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/ini.cpp +++ b/Core/Libraries/Source/WWVegas/WWLib/ini.cpp @@ -1150,8 +1150,7 @@ bool INIClass::Put_TextBlock(char const * section, char const * text) char buffer[128]; - strncpy(buffer, text, 75); - buffer[75] = '\0'; + strlcpy(buffer, text, 76); char b[32]; sprintf(b, "%d", index); @@ -1724,8 +1723,7 @@ int INIClass::Get_String(char const * section, char const * entry, char const * buffer[0] = '\0'; return(0); } else { - strncpy(buffer, defvalue, size); - buffer[size-1] = '\0'; + strlcpy(buffer, defvalue, size); strtrim(buffer); return(strlen(buffer)); } diff --git a/Core/Libraries/Source/debug/CMakeLists.txt b/Core/Libraries/Source/debug/CMakeLists.txt index f81690ac1c..7a74fe27b8 100644 --- a/Core/Libraries/Source/debug/CMakeLists.txt +++ b/Core/Libraries/Source/debug/CMakeLists.txt @@ -33,6 +33,7 @@ target_include_directories(core_debug INTERFACE ) target_link_libraries(core_debug PRIVATE + core_wwcommon core_config corei_always ) diff --git a/Core/Libraries/Source/debug/debug_debug.cpp b/Core/Libraries/Source/debug/debug_debug.cpp index e35f9006ee..a2fbc3b696 100644 --- a/Core/Libraries/Source/debug/debug_debug.cpp +++ b/Core/Libraries/Source/debug/debug_debug.cpp @@ -27,6 +27,7 @@ // Debug class implementation ////////////////////////////////////////////////////////////////////////////// #include "_pch.h" +#include #include #include #include @@ -729,8 +730,7 @@ Debug& Debug::operator<<(const char *str) void Debug::SetPrefixAndRadix(const char *prefix, int radix) { - strncpy(m_prefix,prefix?prefix:"",sizeof(m_prefix)-1); - m_prefix[sizeof(m_prefix)-1]=0; + strlcpy(m_prefix,prefix?prefix:"",sizeof(m_prefix)); m_radix=radix; } @@ -1423,11 +1423,11 @@ void Debug::SetBuildInfo(const char *version, const char *buildDate) { if (version) - strncpy(Instance.m_version,version,sizeof(Instance.m_version)-1); + strlcpy(Instance.m_version,version,sizeof(Instance.m_version)); if (internalVersion) - strncpy(Instance.m_intVersion,internalVersion,sizeof(Instance.m_intVersion)-1); + strlcpy(Instance.m_intVersion,internalVersion,sizeof(Instance.m_intVersion)); if (buildDate) - strncpy(Instance.m_buildDate,buildDate,sizeof(Instance.m_buildDate)-1); + strlcpy(Instance.m_buildDate,buildDate,sizeof(Instance.m_buildDate)); } void Debug::WriteBuildInfo(void) diff --git a/Core/Libraries/Source/debug/debug_io_flat.cpp b/Core/Libraries/Source/debug/debug_io_flat.cpp index 1f1bc85d1a..196a0892aa 100644 --- a/Core/Libraries/Source/debug/debug_io_flat.cpp +++ b/Core/Libraries/Source/debug/debug_io_flat.cpp @@ -27,6 +27,7 @@ // Debug I/O class flat (flat or split log file) ////////////////////////////////////////////////////////////////////////////// #include "_pch.h" +#include "stringex.h" #include #include // needed for placement new prototype @@ -428,8 +429,7 @@ void DebugIOFlat::Execute(class Debug& dbg, const char *cmd, bool structuredCmd, // copy if (argn) { - strncpy(m_copyDir,argv[0],sizeof(m_copyDir)-1); - m_copyDir[sizeof(m_copyDir)-1]=0; + strlcpy(m_copyDir,argv[0],sizeof(m_copyDir)); } } else if (!strcmp(cmd,"splitadd")) @@ -460,11 +460,8 @@ void DebugIOFlat::Execute(class Debug& dbg, const char *cmd, bool structuredCmd, if (!cur->stringTypes) cur->stringTypes=0xffffffff; - strncpy(cur->items,argv[1],sizeof(cur->items)-1); - cur->items[sizeof(cur->items)-1]=0; - - strncpy(cur->name,argv[2],sizeof(cur->name)-1); - cur->name[sizeof(cur->name)-1]=0; + strlcpy(cur->items,argv[1],sizeof(cur->items)); + strlcpy(cur->name,argv[2],sizeof(cur->name)); // create our filename, search for stream with same filename char fn[256]; diff --git a/Core/Libraries/Source/debug/debug_stack.cpp b/Core/Libraries/Source/debug/debug_stack.cpp index e40e573ebc..438be1bfc1 100644 --- a/Core/Libraries/Source/debug/debug_stack.cpp +++ b/Core/Libraries/Source/debug/debug_stack.cpp @@ -27,6 +27,7 @@ // Stack walker ////////////////////////////////////////////////////////////////////////////// #include "_pch.h" +#include "stringex.h" #include // Definitions to allow run-time linking to the dbghelp.dll functions. @@ -250,8 +251,7 @@ void DebugStackwalk::Signature::GetSymbol(unsigned addr, char *p=strrchr(symbolBuffer,'\\'); // use filename only, strip off path p=p?p+1:symbolBuffer; - strncpy(bufMod,p,sizeMod); - bufMod[sizeMod-1]=0; + strlcpy(bufMod,p,sizeMod); } if (relMod) *relMod=addr-modBase; @@ -266,8 +266,7 @@ void DebugStackwalk::Signature::GetSymbol(unsigned addr, DWORD displacement; if (gDbg._SymGetSymFromAddr((HANDLE)GetCurrentProcessId(),addr,&displacement,symPtr)) { - strncpy(bufSym,symPtr->Name,sizeSym); - bufSym[sizeSym-1]=0; + strlcpy(bufSym,symPtr->Name,sizeSym); if (relSym) *relSym=displacement; } @@ -288,8 +287,7 @@ void DebugStackwalk::Signature::GetSymbol(unsigned addr, { char *p=strrchr(line.FileName,'\\'); // use filename only, strip off path p=p?p+1:line.FileName; - strncpy(bufFile,p,sizeFile); - bufFile[sizeFile-1]=0; + strlcpy(bufFile,p,sizeFile); if (linePtr) *linePtr=line.LineNumber; if (relLine) diff --git a/Core/Libraries/Source/profile/CMakeLists.txt b/Core/Libraries/Source/profile/CMakeLists.txt index bad4e7f94c..e04bd14cde 100644 --- a/Core/Libraries/Source/profile/CMakeLists.txt +++ b/Core/Libraries/Source/profile/CMakeLists.txt @@ -27,6 +27,7 @@ target_include_directories(core_profile INTERFACE ) target_link_libraries(core_profile PRIVATE + core_wwcommon core_config corei_always ) diff --git a/Core/Libraries/Source/profile/profile_highlevel.cpp b/Core/Libraries/Source/profile/profile_highlevel.cpp index 06cc22aca6..a97ede2a06 100644 --- a/Core/Libraries/Source/profile/profile_highlevel.cpp +++ b/Core/Libraries/Source/profile/profile_highlevel.cpp @@ -27,6 +27,7 @@ // High level profiling ////////////////////////////////////////////////////////////////////////////// #include "_pch.h" +#include "stringex.h" #include #include @@ -91,8 +92,7 @@ ProfileHighLevel::Block::Block(const char *name) m_idTime=AddProfile(name,NULL,"msec",6,-4); char help[256]; - strncpy(help,name,sizeof(help)); - help[sizeof(help)-1-2]=0; + strlcpy(help, name, sizeof(help) - 2); strcat(help,".c"); AddProfile(help,NULL,"calls",6,0).Increment(); diff --git a/Core/Tools/ImagePacker/Source/ImagePacker.cpp b/Core/Tools/ImagePacker/Source/ImagePacker.cpp index 470117db2d..3796bbcdd4 100644 --- a/Core/Tools/ImagePacker/Source/ImagePacker.cpp +++ b/Core/Tools/ImagePacker/Source/ImagePacker.cpp @@ -46,6 +46,7 @@ #include // USER INCLUDES ////////////////////////////////////////////////////////////// +#include "stringex.h" #include "Common/Debug.h" #include "WWLib/TARGA.H" #include "Resource.h" @@ -844,8 +845,7 @@ void ImagePacker::addImage( char *path ) strcpy( info->m_filenameOnly, c ); info->m_filenameOnlyNoExt = new char[ nameLen - 4 + 1 ]; - strncpy( info->m_filenameOnlyNoExt, c, nameLen - 4 ); - info->m_filenameOnlyNoExt[ nameLen - 4 ] = '\0'; + strlcpy( info->m_filenameOnlyNoExt, c, nameLen - 4 + 1 ); // assign to array m_imageList[ m_imageCount++ ] = info; diff --git a/Generals/Code/GameEngine/Source/Common/Recorder.cpp b/Generals/Code/GameEngine/Source/Common/Recorder.cpp index b80c7abe6b..6182b67d45 100644 --- a/Generals/Code/GameEngine/Source/Common/Recorder.cpp +++ b/Generals/Code/GameEngine/Source/Common/Recorder.cpp @@ -288,7 +288,7 @@ void RecorderClass::cleanUpReplayFile( void ) if (TheGlobalData->m_saveStats) { char fname[_MAX_PATH+1]; - strncpy(fname, TheGlobalData->m_baseStatsDir.str(), _MAX_PATH); + strlcpy(fname, TheGlobalData->m_baseStatsDir.str(), ARRAY_SIZE(fname)); strncat(fname, m_fileName.str(), _MAX_PATH - strlen(fname)); DEBUG_LOG(("Saving replay to %s", fname)); AsciiString oldFname; diff --git a/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp index 6fa3f401fa..4b92df0bfb 100644 --- a/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp +++ b/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp @@ -1177,7 +1177,7 @@ void ThingTemplate::initForLTA(const AsciiString& name) m_nameString = name; char buffer[1024]; - strncpy(buffer, name.str(), sizeof(buffer)); + strlcpy(buffer, name.str(), sizeof(buffer)); int i=0; for (; buffer[i]; i++) { if (buffer[i] == '/') { diff --git a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp index 2c556656d7..a19db1902b 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp @@ -1718,8 +1718,7 @@ WindowMsgHandledType WOLQuickMatchMenuSystem( GameWindow *window, UnsignedInt ms req.QM.discons = numDiscons; - strncpy(req.QM.pings, TheGameSpyInfo->getPingString().str(), 17); - req.QM.pings[16] = 0; + strlcpy(req.QM.pings, TheGameSpyInfo->getPingString().str(), sizeof(req.QM.pings)); req.QM.botID = TheGameSpyConfig->getQMBotID(); req.QM.roomID = TheGameSpyConfig->getQMChannel(); diff --git a/Generals/Code/GameEngine/Source/GameClient/MapUtil.cpp b/Generals/Code/GameEngine/Source/GameClient/MapUtil.cpp index d5b7885e7b..ff604a932f 100644 --- a/Generals/Code/GameEngine/Source/GameClient/MapUtil.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/MapUtil.cpp @@ -95,8 +95,7 @@ static UnsignedInt calcCRC( AsciiString dirName, AsciiString fname ) length = strlen( tempBuf ); if( length >= 4 ) { - memset( filenameBuf, '\0', _MAX_PATH); - strncpy( filenameBuf, tempBuf, length - 4); + strlcpy( filenameBuf, tempBuf, length - 4 + 1); } File *fp; @@ -242,8 +241,7 @@ static Bool loadMap( AsciiString filename ) length = strlen( tempBuf ); if( length >= 4 ) { - memset( filenameBuf, '\0', _MAX_PATH); - strncpy( filenameBuf, tempBuf, length - 4); + strlcpy( filenameBuf, tempBuf, length - 4 + 1); } CachedFileInputStream fileStrm; diff --git a/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp b/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp index 06e9dae3e1..f0d08b7588 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp @@ -483,8 +483,7 @@ void BuddyThreadClass::errorCallback( GPConnection *con, GPErrorArg *arg ) errorResponse.result = arg->result; errorResponse.arg.error.errorCode = arg->errorCode; errorResponse.arg.error.fatal = arg->fatal; - strncpy(errorResponse.arg.error.errorString, arg->errorString, MAX_BUDDY_CHAT_LEN); - errorResponse.arg.error.errorString[MAX_BUDDY_CHAT_LEN-1] = 0; + strlcpy(errorResponse.arg.error.errorString, arg->errorString, MAX_BUDDY_CHAT_LEN); m_isConnecting = m_isConnected = false; TheGameSpyBuddyMessageQueue->addResponse( errorResponse ); if (m_isdeleting) diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp index 89a53cd1b6..07d411939b 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -632,8 +632,7 @@ void LANAPI::RequestGameJoin( LANGameInfo *game, UnsignedInt ip /* = 0 */ ) AsciiString s = ""; GetStringFromRegistry("\\ergc", "", s); - strncpy(msg.GameToJoin.serial, s.str(), g_maxSerialLength); - msg.GameToJoin.serial[g_maxSerialLength-1] = '\0'; + strlcpy(msg.GameToJoin.serial, s.str(), sizeof(msg.GameToJoin.serial)); sendMessage(&msg, ip); @@ -707,7 +706,7 @@ void LANAPI::RequestGameAnnounce( void ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strncpy(reply.GameInfo.options,gameOpts.str(),m_lanMaxOptionsLength); + strlcpy(reply.GameInfo.options,gameOpts.str(), sizeof(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -839,7 +838,7 @@ void LANAPI::RequestGameOptions( AsciiString gameOptions, Bool isPublic, Unsigne LANMessage msg; fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_GAME_OPTIONS; - strncpy(msg.GameOptions.options, gameOptions.str(), m_lanMaxOptionsLength); + strlcpy(msg.GameOptions.options, gameOptions.str(), sizeof(msg.GameOptions.options)); msg.GameOptions.options[m_lanMaxOptionsLength] = 0; sendMessage(&msg, ip); @@ -1075,10 +1074,8 @@ void LANAPI::fillInLANMessage( LANMessage *msg ) wcsncpy(msg->name, m_name.str(), g_lanPlayerNameLength); msg->name[g_lanPlayerNameLength] = 0; - strncpy(msg->userName, m_userName.str(), g_lanLoginNameLength); - msg->userName[g_lanLoginNameLength] = 0; - strncpy(msg->hostName, m_hostName.str(), g_lanHostNameLength); - msg->hostName[g_lanHostNameLength] = 0; + strlcpy(msg->userName, m_userName.str(), sizeof(msg->userName)); + strlcpy(msg->hostName, m_hostName.str(), sizeof(msg->hostName)); } void LANAPI::RequestLobbyLeave( Bool forced ) diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index fe9f70ee29..43550e7a46 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -62,7 +62,7 @@ void LANAPI::handleRequestLocations( LANMessage *msg, UnsignedInt senderIP ) fillInLANMessage( &reply ); reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GenerateGameOptionsString(); - strncpy(reply.GameInfo.options,gameOpts.str(),m_lanMaxOptionsLength); + strlcpy(reply.GameInfo.options, gameOpts.str(), sizeof(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -193,7 +193,7 @@ void LANAPI::handleRequestGameInfo( LANMessage *msg, UnsignedInt senderIP ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strncpy(reply.GameInfo.options,gameOpts.str(),m_lanMaxOptionsLength); + strlcpy(reply.GameInfo.options,gameOpts.str(),sizeof(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp index 76f55e8d0b..3b20bce386 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp @@ -160,8 +160,8 @@ class W3DShadowTexture : public RefCountClass, public HashableClass const char * Get_Name(void) const { return m_namebuf;} void Set_Name(const char *name) - { memset(m_namebuf,0,sizeof(m_namebuf)); //pad with zero so always ends with null character. - strncpy(m_namebuf,name,sizeof(m_namebuf)-1); + { + strlcpy(m_namebuf,name,sizeof(m_namebuf)); } TextureClass *getTexture(void) { return m_texture;} void setTexture(TextureClass *texture) {m_texture = texture;} @@ -1487,7 +1487,7 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) //can be always perpendicular to model's z-axis or projected //onto world geometry. nameLen=strlen(shadowInfo->m_ShadowName); - strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension //Check if we previously added a decal using this texture @@ -1593,7 +1593,7 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow //can be always perpendicular to model's z-axis or projected //onto world geometry. nameLen=strlen(shadowInfo->m_ShadowName); - strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension //Check if we previously added a decal using this texture @@ -1726,7 +1726,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S { strcpy(texture_name,defaultDecalName); } else - { strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension } @@ -1903,7 +1903,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT { strcpy(texture_name,defaultDecalName); } else - { strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension } diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index 72efdf7b6b..34ff71f1d1 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -579,8 +579,8 @@ class W3DShadowGeometry : public RefCountClass, public HashableClass const char * Get_Name(void) const { return m_namebuf;} void Set_Name(const char *name) - { memset(m_namebuf,0,sizeof(m_namebuf)); //pad with zero so always ends with null character. - strncpy(m_namebuf,name,sizeof(m_namebuf)-1); + { + strlcpy(m_namebuf,name,sizeof(m_namebuf)); } Int getMeshCount(void) { return m_meshCount;} W3DShadowGeometryMesh *getMesh(Int index) { return &m_meshList[index];} diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp index fdd14ec1fc..d75fc31008 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp @@ -129,7 +129,7 @@ char const * GameFileClass::Set_Name( char const *filename ) Close(); // save the filename - strncpy( m_filename, filename, _MAX_PATH ); + strlcpy( m_filename, filename, _MAX_PATH ); char name[_MAX_PATH]; const Int EXT_LEN = 32; diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp index 85f8c9b5bb..0c34f99695 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp @@ -126,8 +126,7 @@ Bool W3DTerrainLogic::loadMap( AsciiString filename , Bool query ) length = strlen( tempBuf ); if( length >= 4 ) { - memset( filenameBuf, '\0', _MAX_PATH); - strncpy( filenameBuf, tempBuf, length - 4); + strlcpy( filenameBuf, tempBuf, length - 4 + 1); } // const char *fname = filename.reverseFind('\\'); diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp index d8165cd029..e1dbea9c49 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp @@ -47,7 +47,7 @@ DDSFileClass::DDSFileClass(const char* name,unsigned reduction_factor) DateTime(0), CubeFaceSize(0) { - strncpy(Name,name,sizeof(Name)); + strlcpy(Name,name,sizeof(Name)); // The name could be given in .tga or .dds format, so ensure we're opening .dds... int len=strlen(Name); Name[len-3]='d'; diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index ccd6c9df7f..a94c8d239c 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -2401,8 +2401,7 @@ IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(const char *filename_) // If file not found, try the dds format // else create a surface with missing texture in it char compressed_name[200]; - strncpy(compressed_name,filename_, ARRAY_SIZE(compressed_name)); - compressed_name[ARRAY_SIZE(compressed_name)-1] = '\0'; + strlcpy(compressed_name,filename_, sizeof(compressed_name)); char *ext = strstr(compressed_name, "."); if ( ext && (strlen(ext)==4) && ( (ext[1] == 't') || (ext[1] == 'T') ) && diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp index e78a0f9052..4bf53237c7 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp @@ -165,7 +165,7 @@ class ProxyRecordClass void Init(const W3dHLodSubObjectStruct & w3d_data) { BoneIndex = w3d_data.BoneIndex; - strncpy(Name,w3d_data.Name,sizeof(Name)); + strlcpy(Name,w3d_data.Name,sizeof(Name)); } int Get_Bone_Index(void) { return BoneIndex; } diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp index 60804fd1d4..ca25a66d09 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp @@ -343,8 +343,7 @@ bool HMorphAnimClass::Import(const char *hierarchy_name, TextFileClass &text_des // // Copy the hierarchy name into a class variable // - ::strncpy (HierarchyName, hierarchy_name, W3D_NAME_LEN); - HierarchyName[W3D_NAME_LEN - 1] = 0; + ::strlcpy(HierarchyName, hierarchy_name, W3D_NAME_LEN); // // Attempt to load the new base pose @@ -550,8 +549,8 @@ int HMorphAnimClass::Load_W3D(ChunkLoadClass & cload) cload.Read(&header,sizeof(header)); cload.Close_Chunk(); - strncpy(AnimName,header.Name,sizeof(AnimName)); - strncpy(HierarchyName,header.HierarchyName,sizeof(HierarchyName)); + strlcpy(AnimName,header.Name,sizeof(AnimName)); + strlcpy(HierarchyName,header.HierarchyName,sizeof(HierarchyName)); strcpy(Name,HierarchyName); strcat(Name,"."); strcat(Name,AnimName); @@ -621,9 +620,8 @@ int HMorphAnimClass::Save_W3D(ChunkSaveClass & csave) // init the header data W3dMorphAnimHeaderStruct header; - memset(&header,0,sizeof(header)); - strncpy(header.Name,AnimName,sizeof(header.Name)); - strncpy(header.HierarchyName,HierarchyName,sizeof(header.HierarchyName)); + strlcpy(header.Name,AnimName,sizeof(header.Name)); + strlcpy(header.HierarchyName,HierarchyName,sizeof(header.HierarchyName)); header.FrameCount = FrameCount; header.FrameRate = FrameRate; diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp index fe1e34ecc4..cf0398f0b5 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -219,7 +219,7 @@ int HRawAnimClass::Load_W3D(ChunkLoadClass & cload) WWASSERT(HierarchyName != NULL); WWASSERT(aheader.HierarchyName != NULL); WWASSERT(sizeof(HierarchyName) >= W3D_NAME_LEN); - strncpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); + strlcpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName); if (base_pose == NULL) { diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp index 474ebd9c32..794ef61488 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp @@ -2284,8 +2284,8 @@ WW3DErrorType MeshModelClass::write_header(ChunkSaveClass & csave,MeshSaveContex mesh_name++; } assert( hierarchy_name_len <= W3D_NAME_LEN); - strncpy( header.MeshName, mesh_name, W3D_NAME_LEN); - strncpy( header.ContainerName, name, hierarchy_name_len); + strlcpy( header.MeshName, mesh_name, W3D_NAME_LEN); + strlcpy( header.ContainerName, name, hierarchy_name_len + 1); } else { sprintf(header.MeshName,"UnNamed"); } diff --git a/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp b/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp index 775a9aea7d..ed49810783 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp @@ -239,7 +239,7 @@ void BlendMaterial::updateTextures(void) for (i=WorldHeightMapEdit::getNumTexClasses()-1; i>=0; i--) { char path[_MAX_PATH]; AsciiString uiName = WorldHeightMapEdit::getTexClassUiName(i); - strncpy(path, uiName.str(), _MAX_PATH-2); + strlcpy(path, uiName.str(), _MAX_PATH); addTerrain(path, i, TVI_ROOT); } m_updating = false; diff --git a/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp b/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp index f65721ddcf..679f261a0a 100644 --- a/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp @@ -369,7 +369,7 @@ void TerrainMaterial::updateTextures(WorldHeightMapEdit *pMap) for (i=0; igetNumTexClasses(); i++) { char path[_MAX_PATH]; AsciiString uiName = pMap->getTexClassUiName(i); - strncpy(path, uiName.str(), _MAX_PATH-2); + strlcpy(path, uiName.str(), _MAX_PATH); m_staticThis->addTerrain(path, i, TVI_ROOT); } m_staticThis->m_updating = false; diff --git a/Generals/Code/Tools/WorldBuilder/src/TerrainModal.cpp b/Generals/Code/Tools/WorldBuilder/src/TerrainModal.cpp index f038bf8049..430d7b36d0 100644 --- a/Generals/Code/Tools/WorldBuilder/src/TerrainModal.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/TerrainModal.cpp @@ -234,7 +234,7 @@ void TerrainModal::updateTextures(void) } const char *tName = WorldHeightMapEdit::getTexClassName(i).str(); char path[_MAX_PATH]; - strncpy(path, tName, _MAX_PATH-2); + strlcpy(path, tName, _MAX_PATH); addTerrain(path, i, TVI_ROOT); } setTerrainTreeViewSelection(TVI_ROOT, m_currentFgTexture); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index 99e70f26c5..1bd0d75352 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -288,7 +288,7 @@ void RecorderClass::cleanUpReplayFile( void ) if (TheGlobalData->m_saveStats) { char fname[_MAX_PATH+1]; - strncpy(fname, TheGlobalData->m_baseStatsDir.str(), _MAX_PATH); + strlcpy(fname, TheGlobalData->m_baseStatsDir.str(), ARRAY_SIZE(fname)); strncat(fname, m_fileName.str(), _MAX_PATH - strlen(fname)); DEBUG_LOG(("Saving replay to %s", fname)); AsciiString oldFname; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp index 1e163cfb17..c0fc82f6ed 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp @@ -1316,7 +1316,7 @@ void ThingTemplate::initForLTA(const AsciiString& name) m_nameString = name; char buffer[1024]; - strncpy(buffer, name.str(), sizeof(buffer)); + strlcpy(buffer, name.str(), sizeof(buffer)); int i=0; for (; buffer[i]; i++) { if (buffer[i] == '/') { diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp index d5d0bad5aa..0f609c9093 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLQuickMatchMenu.cpp @@ -1783,8 +1783,7 @@ WindowMsgHandledType WOLQuickMatchMenuSystem( GameWindow *window, UnsignedInt ms req.QM.discons = numDiscons; - strncpy(req.QM.pings, TheGameSpyInfo->getPingString().str(), 17); - req.QM.pings[16] = 0; + strlcpy(req.QM.pings, TheGameSpyInfo->getPingString().str(), sizeof(req.QM.pings)); req.QM.botID = TheGameSpyConfig->getQMBotID(); req.QM.roomID = TheGameSpyConfig->getQMChannel(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp index 611fff670a..08572be74d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp @@ -95,8 +95,7 @@ static UnsignedInt calcCRC( AsciiString dirName, AsciiString fname ) length = strlen( tempBuf ); if( length >= 4 ) { - memset( filenameBuf, '\0', _MAX_PATH); - strncpy( filenameBuf, tempBuf, length - 4); + strlcpy( filenameBuf, tempBuf, length - 4 + 1); } File *fp; @@ -242,8 +241,7 @@ static Bool loadMap( AsciiString filename ) length = strlen( tempBuf ); if( length >= 4 ) { - memset( filenameBuf, '\0', _MAX_PATH); - strncpy( filenameBuf, tempBuf, length - 4); + strlcpy( filenameBuf, tempBuf, length - 4 + 1); } CachedFileInputStream fileStrm; diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp index 338de3ebde..75905f2e09 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp @@ -483,8 +483,7 @@ void BuddyThreadClass::errorCallback( GPConnection *con, GPErrorArg *arg ) errorResponse.result = arg->result; errorResponse.arg.error.errorCode = arg->errorCode; errorResponse.arg.error.fatal = arg->fatal; - strncpy(errorResponse.arg.error.errorString, arg->errorString, MAX_BUDDY_CHAT_LEN); - errorResponse.arg.error.errorString[MAX_BUDDY_CHAT_LEN-1] = 0; + strlcpy(errorResponse.arg.error.errorString, arg->errorString, MAX_BUDDY_CHAT_LEN); m_isConnecting = m_isConnected = false; TheGameSpyBuddyMessageQueue->addResponse( errorResponse ); if (m_isdeleting) diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp index e10a45aa26..93f4c06150 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -632,8 +632,7 @@ void LANAPI::RequestGameJoin( LANGameInfo *game, UnsignedInt ip /* = 0 */ ) AsciiString s = ""; GetStringFromRegistry("\\ergc", "", s); - strncpy(msg.GameToJoin.serial, s.str(), g_maxSerialLength); - msg.GameToJoin.serial[g_maxSerialLength-1] = '\0'; + strlcpy(msg.GameToJoin.serial, s.str(), sizeof(msg.GameToJoin.serial)); sendMessage(&msg, ip); @@ -707,7 +706,7 @@ void LANAPI::RequestGameAnnounce( void ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strncpy(reply.GameInfo.options,gameOpts.str(),m_lanMaxOptionsLength); + strlcpy(reply.GameInfo.options,gameOpts.str(), sizeof(reply.GameOptions.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -839,8 +838,7 @@ void LANAPI::RequestGameOptions( AsciiString gameOptions, Bool isPublic, Unsigne LANMessage msg; fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_GAME_OPTIONS; - strncpy(msg.GameOptions.options, gameOptions.str(), m_lanMaxOptionsLength); - msg.GameOptions.options[m_lanMaxOptionsLength] = 0; + strlcpy(msg.GameOptions.options, gameOptions.str(), sizeof(msg.GameOptions.options)); sendMessage(&msg, ip); m_lastGameopt = gameOptions; @@ -1075,10 +1073,8 @@ void LANAPI::fillInLANMessage( LANMessage *msg ) wcsncpy(msg->name, m_name.str(), g_lanPlayerNameLength); msg->name[g_lanPlayerNameLength] = 0; - strncpy(msg->userName, m_userName.str(), g_lanLoginNameLength); - msg->userName[g_lanLoginNameLength] = 0; - strncpy(msg->hostName, m_hostName.str(), g_lanHostNameLength); - msg->hostName[g_lanHostNameLength] = 0; + strlcpy(msg->userName, m_userName.str(), sizeof(msg->userName)); + strlcpy(msg->hostName, m_hostName.str(), sizeof(msg->hostName)); } void LANAPI::RequestLobbyLeave( Bool forced ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index 125895fd95..fb3de6fed0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -62,7 +62,7 @@ void LANAPI::handleRequestLocations( LANMessage *msg, UnsignedInt senderIP ) fillInLANMessage( &reply ); reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GenerateGameOptionsString(); - strncpy(reply.GameInfo.options,gameOpts.str(),m_lanMaxOptionsLength); + strlcpy(reply.GameInfo.options,gameOpts.str(),sizeof(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -193,7 +193,7 @@ void LANAPI::handleRequestGameInfo( LANMessage *msg, UnsignedInt senderIP ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strncpy(reply.GameInfo.options,gameOpts.str(),m_lanMaxOptionsLength); + strlcpy(reply.GameInfo.options,gameOpts.str(), sizeof(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp index 5e6a870399..31aa0d9962 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp @@ -160,8 +160,8 @@ class W3DShadowTexture : public RefCountClass, public HashableClass const char * Get_Name(void) const { return m_namebuf;} void Set_Name(const char *name) - { memset(m_namebuf,0,sizeof(m_namebuf)); //pad with zero so always ends with null character. - strncpy(m_namebuf,name,sizeof(m_namebuf)-1); + { + strlcpy(m_namebuf,name,sizeof(m_namebuf)); } TextureClass *getTexture(void) { return m_texture;} void setTexture(TextureClass *texture) {m_texture = texture;} @@ -1487,7 +1487,7 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) //can be always perpendicular to model's z-axis or projected //onto world geometry. nameLen=strlen(shadowInfo->m_ShadowName); - strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension //Check if we previously added a decal using this texture @@ -1593,7 +1593,7 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow //can be always perpendicular to model's z-axis or projected //onto world geometry. nameLen=strlen(shadowInfo->m_ShadowName); - strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension //Check if we previously added a decal using this texture @@ -1726,7 +1726,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S { strcpy(texture_name,defaultDecalName); } else - { strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension } @@ -1903,7 +1903,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT { strcpy(texture_name,defaultDecalName); } else - { strncpy(texture_name,shadowInfo->m_ShadowName,nameLen); + { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); strcpy(texture_name+nameLen,".tga"); //append texture extension } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index d6eaa6030f..28bb07e9ab 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -599,8 +599,8 @@ class W3DShadowGeometry : public RefCountClass, public HashableClass const char * Get_Name(void) const { return m_namebuf;} void Set_Name(const char *name) - { memset(m_namebuf,0,sizeof(m_namebuf)); //pad with zero so always ends with null character. - strncpy(m_namebuf,name,sizeof(m_namebuf)-1); + { + strlcpy(m_namebuf,name,sizeof(m_namebuf)); } Int getMeshCount(void) { return m_meshCount;} W3DShadowGeometryMesh *getMesh(Int index) { return &m_meshList[index];} diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp index 23e043019a..4c9336143f 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp @@ -144,7 +144,7 @@ char const * GameFileClass::Set_Name( char const *filename ) Close(); // save the filename - strncpy( m_filename, filename, _MAX_PATH ); + strlcpy( m_filename, filename, _MAX_PATH ); char name[_MAX_PATH]; const Int EXT_LEN = 32; diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp index 08a24c7851..35b3c12824 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp @@ -126,8 +126,7 @@ Bool W3DTerrainLogic::loadMap( AsciiString filename , Bool query ) length = strlen( tempBuf ); if( length >= 4 ) { - memset( filenameBuf, '\0', _MAX_PATH); - strncpy( filenameBuf, tempBuf, length - 4); + strlcpy( filenameBuf, tempBuf, length - 4 + 1); } // const char *fname = filename.reverseFind('\\'); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp index d39237856c..252c3f17e5 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp @@ -47,7 +47,7 @@ DDSFileClass::DDSFileClass(const char* name,unsigned reduction_factor) DateTime(0), CubeFaceSize(0) { - strncpy(Name,name,sizeof(Name)); + strlcpy(Name,name,sizeof(Name)); // The name could be given in .tga or .dds format, so ensure we're opening .dds... int len=strlen(Name); Name[len-3]='d'; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 6aa7ec4ab3..33adbebd63 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -2940,8 +2940,7 @@ IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(const char *filename_) // If file not found, try the dds format // else create a surface with missing texture in it char compressed_name[200]; - strncpy(compressed_name,filename_, ARRAY_SIZE(compressed_name)); - compressed_name[ARRAY_SIZE(compressed_name)-1] = '\0'; + strlcpy(compressed_name,filename_, sizeof(compressed_name)); char *ext = strstr(compressed_name, "."); if ( ext && (strlen(ext)==4) && ( (ext[1] == 't') || (ext[1] == 'T') ) && diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp index 261d70a2ff..9f84919dbd 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp @@ -165,7 +165,7 @@ class ProxyRecordClass void Init(const W3dHLodSubObjectStruct & w3d_data) { BoneIndex = w3d_data.BoneIndex; - strncpy(Name,w3d_data.Name,sizeof(Name)); + strlcpy(Name,w3d_data.Name,sizeof(Name)); } int Get_Bone_Index(void) { return BoneIndex; } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp index b8ed2bfc32..be53ca5e63 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp @@ -343,8 +343,7 @@ bool HMorphAnimClass::Import(const char *hierarchy_name, TextFileClass &text_des // // Copy the hierarchy name into a class variable // - ::strncpy (HierarchyName, hierarchy_name, W3D_NAME_LEN); - HierarchyName[W3D_NAME_LEN - 1] = 0; + strlcpy (HierarchyName, hierarchy_name, W3D_NAME_LEN); // // Attempt to load the new base pose @@ -549,8 +548,8 @@ int HMorphAnimClass::Load_W3D(ChunkLoadClass & cload) cload.Read(&header,sizeof(header)); cload.Close_Chunk(); - strncpy(AnimName,header.Name,sizeof(AnimName)); - strncpy(HierarchyName,header.HierarchyName,sizeof(HierarchyName)); + strlcpy(AnimName,header.Name,sizeof(AnimName)); + strlcpy(HierarchyName,header.HierarchyName,sizeof(HierarchyName)); strcpy(Name,HierarchyName); strcat(Name,"."); strcat(Name,AnimName); @@ -620,9 +619,8 @@ int HMorphAnimClass::Save_W3D(ChunkSaveClass & csave) // init the header data W3dMorphAnimHeaderStruct header; - memset(&header,0,sizeof(header)); - strncpy(header.Name,AnimName,sizeof(header.Name)); - strncpy(header.HierarchyName,HierarchyName,sizeof(header.HierarchyName)); + strlcpy(header.Name,AnimName,sizeof(header.Name)); + strlcpy(header.HierarchyName,HierarchyName,sizeof(header.HierarchyName)); header.FrameCount = FrameCount; header.FrameRate = FrameRate; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp index 1f61bb410c..0a625a64ba 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -219,7 +219,7 @@ int HRawAnimClass::Load_W3D(ChunkLoadClass & cload) WWASSERT(HierarchyName != NULL); WWASSERT(aheader.HierarchyName != NULL); WWASSERT(sizeof(HierarchyName) >= W3D_NAME_LEN); - strncpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); + strlcpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName); if (base_pose == NULL) { diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp index c1447792e8..a54243bd65 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp @@ -2330,8 +2330,8 @@ WW3DErrorType MeshModelClass::write_header(ChunkSaveClass & csave,MeshSaveContex mesh_name++; } assert( hierarchy_name_len <= W3D_NAME_LEN); - strncpy( header.MeshName, mesh_name, W3D_NAME_LEN); - strncpy( header.ContainerName, name, hierarchy_name_len); + strlcpy( header.MeshName, mesh_name, W3D_NAME_LEN); + strlcpy( header.ContainerName, name, hierarchy_name_len + 1); } else { sprintf(header.MeshName,"UnNamed"); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp index 170b9ca18b..e8ea32a206 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp @@ -239,7 +239,7 @@ void BlendMaterial::updateTextures(void) for (i=WorldHeightMapEdit::getNumTexClasses()-1; i>=0; i--) { char path[_MAX_PATH]; AsciiString uiName = WorldHeightMapEdit::getTexClassUiName(i); - strncpy(path, uiName.str(), _MAX_PATH-2); + strlcpy(path, uiName.str(), _MAX_PATH); addTerrain(path, i, TVI_ROOT); } m_updating = false; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/EditAction.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/EditAction.cpp index 7b51772521..bae26db5da 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/EditAction.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/EditAction.cpp @@ -140,8 +140,7 @@ BOOL EditAction::OnInitDialog() count = 0; } if (count>0) { - strncpy(prefix, nameStart, count); - prefix[count-1] = 0; + strlcpy(prefix, nameStart, count); parent = findOrAdd(&m_actionTreeView, parent, prefix); } } while (count>0); @@ -178,8 +177,7 @@ BOOL EditAction::OnInitDialog() count = 0; } if (count>0) { - strncpy(prefix, nameStart, count); - prefix[count-1] = 0; + strlcpy(prefix, nameStart, count); parent = findOrAdd(&m_actionTreeView, parent, prefix); } } while (count>0); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/EditCondition.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/EditCondition.cpp index b591d856a3..6df3962f51 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/EditCondition.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/EditCondition.cpp @@ -152,8 +152,7 @@ BOOL EditCondition::OnInitDialog() count = 0; } if (count>0) { - strncpy(prefix, nameStart, count); - prefix[count-1] = 0; + strlcpy(prefix, nameStart, count); parent = findOrAdd(&m_conditionTreeView, parent, prefix); } } while (count>0); @@ -190,8 +189,7 @@ BOOL EditCondition::OnInitDialog() count = 0; } if (count>0) { - strncpy(prefix, nameStart, count); - prefix[count-1] = 0; + strlcpy(prefix, nameStart, count); parent = findOrAdd(&m_conditionTreeView, parent, prefix); } } while (count>0); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp index ea444f637a..69299bc306 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp @@ -369,7 +369,7 @@ void TerrainMaterial::updateTextures(WorldHeightMapEdit *pMap) for (i=0; igetNumTexClasses(); i++) { char path[_MAX_PATH]; AsciiString uiName = pMap->getTexClassUiName(i); - strncpy(path, uiName.str(), _MAX_PATH-2); + strlcpy(path, uiName.str(), _MAX_PATH); m_staticThis->addTerrain(path, i, TVI_ROOT); } m_staticThis->m_updating = false; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp index ac4dfb619f..17afe7ba5e 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp @@ -234,7 +234,7 @@ void TerrainModal::updateTextures(void) } const char *tName = WorldHeightMapEdit::getTexClassName(i).str(); char path[_MAX_PATH]; - strncpy(path, tName, _MAX_PATH-2); + strlcpy(path, tName, _MAX_PATH); addTerrain(path, i, TVI_ROOT); } setTerrainTreeViewSelection(TVI_ROOT, m_currentFgTexture); From ec72413e54550139aced9d7d808182d9f9e0430e Mon Sep 17 00:00:00 2001 From: Bart Roossien Date: Tue, 23 Sep 2025 20:44:49 +0200 Subject: [PATCH 2/5] changing sizeof() back to ARRAY_Size --- Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp | 10 +++++----- .../GameEngine/Source/GameNetwork/LANAPIhandlers.cpp | 4 ++-- .../Code/GameEngine/Source/GameNetwork/LANAPI.cpp | 10 +++++----- .../GameEngine/Source/GameNetwork/LANAPIhandlers.cpp | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp index 07d411939b..e6355f3a42 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -632,7 +632,7 @@ void LANAPI::RequestGameJoin( LANGameInfo *game, UnsignedInt ip /* = 0 */ ) AsciiString s = ""; GetStringFromRegistry("\\ergc", "", s); - strlcpy(msg.GameToJoin.serial, s.str(), sizeof(msg.GameToJoin.serial)); + strlcpy(msg.GameToJoin.serial, s.str(), ARRAY_SIZE(msg.GameToJoin.serial)); sendMessage(&msg, ip); @@ -706,7 +706,7 @@ void LANAPI::RequestGameAnnounce( void ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strlcpy(reply.GameInfo.options,gameOpts.str(), sizeof(reply.GameInfo.options)); + strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -838,7 +838,7 @@ void LANAPI::RequestGameOptions( AsciiString gameOptions, Bool isPublic, Unsigne LANMessage msg; fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_GAME_OPTIONS; - strlcpy(msg.GameOptions.options, gameOptions.str(), sizeof(msg.GameOptions.options)); + strlcpy(msg.GameOptions.options, gameOptions.str(), ARRAY_SIZE(msg.GameOptions.options)); msg.GameOptions.options[m_lanMaxOptionsLength] = 0; sendMessage(&msg, ip); @@ -1074,8 +1074,8 @@ void LANAPI::fillInLANMessage( LANMessage *msg ) wcsncpy(msg->name, m_name.str(), g_lanPlayerNameLength); msg->name[g_lanPlayerNameLength] = 0; - strlcpy(msg->userName, m_userName.str(), sizeof(msg->userName)); - strlcpy(msg->hostName, m_hostName.str(), sizeof(msg->hostName)); + strlcpy(msg->userName, m_userName.str(), ARRAY_SIZE(msg->userName)); + strlcpy(msg->hostName, m_hostName.str(), ARRAY_SIZE(msg->hostName)); } void LANAPI::RequestLobbyLeave( Bool forced ) diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index 43550e7a46..ce16788bd4 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -62,7 +62,7 @@ void LANAPI::handleRequestLocations( LANMessage *msg, UnsignedInt senderIP ) fillInLANMessage( &reply ); reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GenerateGameOptionsString(); - strlcpy(reply.GameInfo.options, gameOpts.str(), sizeof(reply.GameInfo.options)); + strlcpy(reply.GameInfo.options, gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -193,7 +193,7 @@ void LANAPI::handleRequestGameInfo( LANMessage *msg, UnsignedInt senderIP ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strlcpy(reply.GameInfo.options,gameOpts.str(),sizeof(reply.GameInfo.options)); + strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp index 93f4c06150..908e025a5d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -632,7 +632,7 @@ void LANAPI::RequestGameJoin( LANGameInfo *game, UnsignedInt ip /* = 0 */ ) AsciiString s = ""; GetStringFromRegistry("\\ergc", "", s); - strlcpy(msg.GameToJoin.serial, s.str(), sizeof(msg.GameToJoin.serial)); + strlcpy(msg.GameToJoin.serial, s.str(), ARRAY_SIZE(msg.GameToJoin.serial)); sendMessage(&msg, ip); @@ -706,7 +706,7 @@ void LANAPI::RequestGameAnnounce( void ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strlcpy(reply.GameInfo.options,gameOpts.str(), sizeof(reply.GameOptions.options)); + strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameOptions.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -838,7 +838,7 @@ void LANAPI::RequestGameOptions( AsciiString gameOptions, Bool isPublic, Unsigne LANMessage msg; fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_GAME_OPTIONS; - strlcpy(msg.GameOptions.options, gameOptions.str(), sizeof(msg.GameOptions.options)); + strlcpy(msg.GameOptions.options, gameOptions.str(), ARRAY_SIZE(msg.GameOptions.options)); sendMessage(&msg, ip); m_lastGameopt = gameOptions; @@ -1073,8 +1073,8 @@ void LANAPI::fillInLANMessage( LANMessage *msg ) wcsncpy(msg->name, m_name.str(), g_lanPlayerNameLength); msg->name[g_lanPlayerNameLength] = 0; - strlcpy(msg->userName, m_userName.str(), sizeof(msg->userName)); - strlcpy(msg->hostName, m_hostName.str(), sizeof(msg->hostName)); + strlcpy(msg->userName, m_userName.str(), ARRAY_SIZE(msg->userName)); + strlcpy(msg->hostName, m_hostName.str(), ARRAY_SIZE(msg->hostName)); } void LANAPI::RequestLobbyLeave( Bool forced ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index fb3de6fed0..5291b6b784 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -62,7 +62,7 @@ void LANAPI::handleRequestLocations( LANMessage *msg, UnsignedInt senderIP ) fillInLANMessage( &reply ); reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GenerateGameOptionsString(); - strlcpy(reply.GameInfo.options,gameOpts.str(),sizeof(reply.GameInfo.options)); + strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); @@ -193,7 +193,7 @@ void LANAPI::handleRequestGameInfo( LANMessage *msg, UnsignedInt senderIP ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); - strlcpy(reply.GameInfo.options,gameOpts.str(), sizeof(reply.GameInfo.options)); + strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); reply.GameInfo.gameName[g_lanGameNameLength] = 0; reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); From c4433a06051ef6c94a2e1422494634004e6b2873 Mon Sep 17 00:00:00 2001 From: Bart Roossien Date: Tue, 23 Sep 2025 20:51:32 +0200 Subject: [PATCH 3/5] Essentially this is a strcpy now. --- .../GameClient/Shadow/W3DProjectedShadow.cpp | 45 +++++++++---------- .../GameClient/Shadow/W3DProjectedShadow.cpp | 45 +++++++++---------- 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp index 3b20bce386..78ce6914a3 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp @@ -1477,8 +1477,7 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) Real decalSizeY=0.0f; Bool allowSunDirection=FALSE; - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; if (!shadowInfo) return NULL; //right now we require hardware render-to-texture support @@ -1486,9 +1485,8 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1583,8 +1581,7 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow Real decalOffsetY=0.0f; Bool allowSunDirection=FALSE; - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; if (!robj || !shadowInfo) return NULL; //right now we require hardware render-to-texture support @@ -1592,9 +1589,8 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1706,8 +1702,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S Real decalOffsetY=0.0f; Bool allowSunDirection=FALSE; - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; if (!m_dynamicRenderTarget || !robj || !TheGlobalData->m_useShadowDecals) @@ -1721,13 +1716,14 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S { //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - if (nameLen <= 1) //no texture name given, use same as object - { strcpy(texture_name,defaultDecalName); + if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object + { + strcpy(texture_name, defaultDecalName); } else - { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + { + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1891,20 +1887,19 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT Real decalOffsetX=0.0f; Real decalOffsetY=0.0f; const Real defaultWidth = 10.0f; - - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - if (nameLen <= 1) //no texture name given, use same as object - { strcpy(texture_name,defaultDecalName); + if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object + { + strcpy(texture_name,defaultDecalName); } else - { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + { + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp index 31aa0d9962..1cbc488232 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp @@ -1477,8 +1477,7 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) Real decalSizeY=0.0f; Bool allowSunDirection=FALSE; - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; if (!shadowInfo) return NULL; //right now we require hardware render-to-texture support @@ -1486,9 +1485,8 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1583,8 +1581,7 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow Real decalOffsetY=0.0f; Bool allowSunDirection=FALSE; - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; if (!robj || !shadowInfo) return NULL; //right now we require hardware render-to-texture support @@ -1592,9 +1589,8 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1706,8 +1702,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S Real decalOffsetY=0.0f; Bool allowSunDirection=FALSE; - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; if (!m_dynamicRenderTarget || !robj || !TheGlobalData->m_useShadowDecals) @@ -1721,13 +1716,14 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S { //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - if (nameLen <= 1) //no texture name given, use same as object - { strcpy(texture_name,defaultDecalName); + if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object + { + strcpy(texture_name, defaultDecalName); } else - { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + { + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1891,20 +1887,19 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT Real decalOffsetX=0.0f; Real decalOffsetY=0.0f; const Real defaultWidth = 10.0f; - - Char texture_name[64]; - Int nameLen; + Char texture_name[ARRAY_SIZE(shadowInfo->m_ShadowName)]; //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - nameLen=strlen(shadowInfo->m_ShadowName); - if (nameLen <= 1) //no texture name given, use same as object - { strcpy(texture_name,defaultDecalName); + if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object + { + strcpy(texture_name, defaultDecalName); } else - { strlcpy(texture_name,shadowInfo->m_ShadowName,nameLen + 1); - strcpy(texture_name+nameLen,".tga"); //append texture extension + { + strcpy(texture_name, shadowInfo->m_ShadowName); + strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); From bd1b0e8db37b2d42d16cf3772bfea5010936e361 Mon Sep 17 00:00:00 2001 From: Bart Roossien Date: Tue, 7 Oct 2025 08:27:20 +0200 Subject: [PATCH 4/5] Some fixes --- Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP | 3 +-- .../Source/profile/profile_highlevel.cpp | 4 ++-- .../GameClient/Shadow/W3DProjectedShadow.cpp | 16 ++++++++-------- .../GameClient/Shadow/W3DProjectedShadow.cpp | 16 ++++++++-------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP b/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP index 12b4c520bd..2cea001161 100644 --- a/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP +++ b/Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP @@ -1831,8 +1831,7 @@ bool Prepare_Directories(const char *rootdir, const char *filename) const char *cptr=filename; while(cptr=strchr(cptr,'\\')) { - memset(tempstr,0,256); - strlcpy(tempstr,filename,cptr-filename); + strlcpy(tempstr,filename,cptr-filename + 1); sprintf(newdir,"%s\\%s",rootdir, tempstr); if (!CreateDirectory(newdir, NULL)) return false; diff --git a/Core/Libraries/Source/profile/profile_highlevel.cpp b/Core/Libraries/Source/profile/profile_highlevel.cpp index a97ede2a06..f99ed37c1b 100644 --- a/Core/Libraries/Source/profile/profile_highlevel.cpp +++ b/Core/Libraries/Source/profile/profile_highlevel.cpp @@ -92,8 +92,8 @@ ProfileHighLevel::Block::Block(const char *name) m_idTime=AddProfile(name,NULL,"msec",6,-4); char help[256]; - strlcpy(help, name, sizeof(help) - 2); - strcat(help,".c"); + strlcpy(help, name, sizeof(help) - 3); + strlcat(help, ".c", sizeof(help)); AddProfile(help,NULL,"calls",6,0).Increment(); ProfileGetTime(m_start); diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp index 78ce6914a3..3f36d54e3d 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp @@ -1485,8 +1485,8 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1589,8 +1589,8 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1722,8 +1722,8 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S } else { - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1898,8 +1898,8 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT } else { - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp index 1cbc488232..33c0782c72 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp @@ -1485,8 +1485,8 @@ Shadow* W3DProjectedShadowManager::addDecal(Shadow::ShadowTypeInfo *shadowInfo) //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1589,8 +1589,8 @@ Shadow* W3DProjectedShadowManager::addDecal(RenderObjClass *robj, Shadow::Shadow //simple decal using the premade texture specified. //can be always perpendicular to model's z-axis or projected //onto world geometry. - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); //Check if we previously added a decal using this texture st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1722,8 +1722,8 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S } else { - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1898,8 +1898,8 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT } else { - strcpy(texture_name, shadowInfo->m_ShadowName); - strlcpy(texture_name, ".tga", ARRAY_SIZE(texture_name)); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); + strlcat(texture_name, ".tga", ARRAY_SIZE(texture_name)); } st=m_W3DShadowTextureManager->getTexture(texture_name); From 1d5ba5c20cd86e3c4ab8868217a86b017cc6733f Mon Sep 17 00:00:00 2001 From: Bart Roossien Date: Tue, 14 Oct 2025 15:27:38 +0200 Subject: [PATCH 5/5] Fixes based on feedback --- Core/Libraries/Source/debug/CMakeLists.txt | 2 +- Core/Libraries/Source/profile/CMakeLists.txt | 2 +- Core/Libraries/Source/profile/profile_highlevel.cpp | 2 +- Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp | 2 +- GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/Libraries/Source/debug/CMakeLists.txt b/Core/Libraries/Source/debug/CMakeLists.txt index 7a74fe27b8..cb2cdcc6f3 100644 --- a/Core/Libraries/Source/debug/CMakeLists.txt +++ b/Core/Libraries/Source/debug/CMakeLists.txt @@ -33,7 +33,7 @@ target_include_directories(core_debug INTERFACE ) target_link_libraries(core_debug PRIVATE - core_wwcommon core_config + core_wwcommon corei_always ) diff --git a/Core/Libraries/Source/profile/CMakeLists.txt b/Core/Libraries/Source/profile/CMakeLists.txt index e04bd14cde..b2b93c3a6c 100644 --- a/Core/Libraries/Source/profile/CMakeLists.txt +++ b/Core/Libraries/Source/profile/CMakeLists.txt @@ -27,7 +27,7 @@ target_include_directories(core_profile INTERFACE ) target_link_libraries(core_profile PRIVATE - core_wwcommon core_config + core_wwcommon corei_always ) diff --git a/Core/Libraries/Source/profile/profile_highlevel.cpp b/Core/Libraries/Source/profile/profile_highlevel.cpp index f99ed37c1b..f091529789 100644 --- a/Core/Libraries/Source/profile/profile_highlevel.cpp +++ b/Core/Libraries/Source/profile/profile_highlevel.cpp @@ -92,7 +92,7 @@ ProfileHighLevel::Block::Block(const char *name) m_idTime=AddProfile(name,NULL,"msec",6,-4); char help[256]; - strlcpy(help, name, sizeof(help) - 3); + strlcpy(help, name, sizeof(help) - 2); strlcat(help, ".c", sizeof(help)); AddProfile(help,NULL,"calls",6,0).Increment(); diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp index 794ef61488..d950ec4d04 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp @@ -2283,7 +2283,7 @@ WW3DErrorType MeshModelClass::write_header(ChunkSaveClass & csave,MeshSaveContex hierarchy_name_len = (int)mesh_name - (int)name; mesh_name++; } - assert( hierarchy_name_len <= W3D_NAME_LEN); + assert( hierarchy_name_len < W3D_NAME_LEN); strlcpy( header.MeshName, mesh_name, W3D_NAME_LEN); strlcpy( header.ContainerName, name, hierarchy_name_len + 1); } else { diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp index a54243bd65..b6dfc18e66 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp @@ -2329,7 +2329,7 @@ WW3DErrorType MeshModelClass::write_header(ChunkSaveClass & csave,MeshSaveContex hierarchy_name_len = (int)mesh_name - (int)name; mesh_name++; } - assert( hierarchy_name_len <= W3D_NAME_LEN); + assert( hierarchy_name_len < W3D_NAME_LEN); strlcpy( header.MeshName, mesh_name, W3D_NAME_LEN); strlcpy( header.ContainerName, name, hierarchy_name_len + 1); } else {