From b7b9c83976215bb94268ecdc14555e5e0a862071 Mon Sep 17 00:00:00 2001 From: Skyaero <21192585+Skyaero42@users.noreply.github.com> Date: Wed, 19 Nov 2025 21:01:42 +0100 Subject: [PATCH 1/2] chore: Convert strlcpy to strcpy with static_assert --- Core/Libraries/Source/WWVegas/WWLib/TARGA.cpp | 2 +- Generals/Code/GameEngine/Source/Common/INI/INI.cpp | 3 ++- Generals/Code/GameEngine/Source/Common/PerfTimer.cpp | 3 ++- .../Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp | 6 ++++-- Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp | 7 ++++--- GeneralsMD/Code/GameEngine/Include/Common/INI.h | 2 +- GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp | 3 ++- GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp | 3 ++- .../Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp | 6 ++++-- .../Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp | 7 ++++--- 10 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWLib/TARGA.cpp b/Core/Libraries/Source/WWVegas/WWLib/TARGA.cpp index 18fbd166807..de3d8773d1b 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; - strlcpy(mExtension.SoftID, "Denzil's Targa Code", sizeof(mExtension.SoftID)); + strcpy(mExtension.SoftID, "Denzil's Targa Code"); mExtension.SoftVer.Number = (1 * 100); mExtension.SoftVer.Letter = 0; diff --git a/Generals/Code/GameEngine/Source/Common/INI/INI.cpp b/Generals/Code/GameEngine/Source/Common/INI/INI.cpp index 3aca266605e..628a9453acb 100644 --- a/Generals/Code/GameEngine/Source/Common/INI/INI.cpp +++ b/Generals/Code/GameEngine/Source/Common/INI/INI.cpp @@ -404,7 +404,8 @@ UnsignedInt INI::load( AsciiString filename, INILoadType loadType, Xfer *pXfer ) if (parse) { #ifdef DEBUG_CRASHING - strlcpy(m_curBlockStart, m_buffer, ARRAY_SIZE(m_curBlockStart)); + static_assert(ARRAY_SIZE(m_curBlockStart) >= ARRAY_SIZE(m_buffer), "Incorrect array size"); + strcpy(m_curBlockStart, m_buffer); #endif try { (*parse)( this ); diff --git a/Generals/Code/GameEngine/Source/Common/PerfTimer.cpp b/Generals/Code/GameEngine/Source/Common/PerfTimer.cpp index 41e5557df04..f65abb69af7 100644 --- a/Generals/Code/GameEngine/Source/Common/PerfTimer.cpp +++ b/Generals/Code/GameEngine/Source/Common/PerfTimer.cpp @@ -272,7 +272,8 @@ void PerfGather::reset() strlcpy(s_buf, fname, ARRAY_SIZE(s_buf); char tmp[256]; - strlcpy(tmp, s_buf, ARRAY_SIZE(tmp)); + static_assert(ARRAY_SIZE(tmp) >= ARRAY_SIZE(s_buf), "Incorrect array size"); + strcpy(tmp, s_buf); strlcat(tmp, ".csv", ARRAY_SIZE(tmp)); s_perfStatsFile = fopen(tmp, "w"); diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp index 87b28837ea0..27ea79983ce 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp @@ -623,8 +623,10 @@ int HMorphAnimClass::Save_W3D(ChunkSaveClass & csave) // init the header data W3dMorphAnimHeaderStruct header; - strlcpy(header.Name,AnimName,sizeof(header.Name)); - strlcpy(header.HierarchyName,HierarchyName,sizeof(header.HierarchyName)); + static_assert(ARRAY_SIZE(header.Name) >= ARRAY_SIZE(AnimName), "Incorrect array size"); + static_assert(ARRAY_SIZE(header.HierarchyName) >= ARRAY_SIZE(HierarchyName), "Incorrect array size"); + strcpy(header.Name, AnimName); + strcpy(header.HierarchyName, 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 d2dfd938621..5cc6d75dcfb 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -211,15 +211,16 @@ int HRawAnimClass::Load_W3D(ChunkLoadClass & cload) pre30 = true; } - strlcpy(Name, aheader.HierarchyName, ARRAY_SIZE(Name)); + static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); + strcpy(Name, aheader.HierarchyName); strlcat(Name, ".", ARRAY_SIZE(Name)); strlcat(Name, aheader.Name, ARRAY_SIZE(Name)); // TSS chasing crash bug 05/26/99 WWASSERT(HierarchyName != NULL); WWASSERT(aheader.HierarchyName != NULL); - WWASSERT(sizeof(HierarchyName) >= W3D_NAME_LEN); - strlcpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); + static_assert(ARRAY_SIZE(HierarchyName) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); + strcpy(HierarchyName, aheader.HierarchyName); HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName); if (base_pose == NULL) { diff --git a/GeneralsMD/Code/GameEngine/Include/Common/INI.h b/GeneralsMD/Code/GameEngine/Include/Common/INI.h index 957fd56baef..182df0ad3ff 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/INI.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/INI.h @@ -420,6 +420,6 @@ class INI const char *m_blockEndToken; ///< token to represent end of data block Bool m_endOfFile; ///< TRUE when we've hit EOF #ifdef DEBUG_CRASHING - char m_curBlockStart[ INI_MAX_CHARS_PER_LINE ]; ///< first line of cur block + char m_curBlockStart[ INI_MAX_CHARS_PER_LINE+1 ]; ///< first line of cur block #endif }; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp index b1de518e711..890eeb4f650 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp @@ -411,7 +411,8 @@ UnsignedInt INI::load( AsciiString filename, INILoadType loadType, Xfer *pXfer ) if (parse) { #ifdef DEBUG_CRASHING - strlcpy(m_curBlockStart, m_buffer, ARRAY_SIZE(m_curBlockStart)); + static_assert(ARRAY_SIZE(m_curBlockStart) >= ARRAY_SIZE(m_buffer), "Incorrect array size"); + strcpy(m_curBlockStart, m_buffer); #endif try { (*parse)( this ); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp index e18d2c8eabc..2bec94d9593 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp @@ -352,7 +352,8 @@ void PerfGather::reset() strlcpy(s_buf, fname, ARRAY_SIZE(s_buf); char tmp[256]; - strlcpy(tmp, s_buf, ARRAY_SIZE(tmp)); + static_assert(ARRAY_SIZE(tmp) >= ARRAY_SIZE(s_buf), "Incorrect array size"); + strcpy(tmp, s_buf); strlcat(tmp, ".csv", ARRAY_SIZE(tmp)); s_perfStatsFile = fopen(tmp, "w"); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp index 488bb4e72a0..af10ea6633e 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp @@ -622,8 +622,10 @@ int HMorphAnimClass::Save_W3D(ChunkSaveClass & csave) // init the header data W3dMorphAnimHeaderStruct header; - strlcpy(header.Name,AnimName,sizeof(header.Name)); - strlcpy(header.HierarchyName,HierarchyName,sizeof(header.HierarchyName)); + static_assert(ARRAY_SIZE(header.Name) >= ARRAY_SIZE(AnimName), "Incorrect array size"); + static_assert(ARRAY_SIZE(header.HierarchyName) >= ARRAY_SIZE(HierarchyName), "Incorrect array size"); + strcpy(header.Name, AnimName); + strcpy(header.HierarchyName, 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 2a76881dd35..e6fd62fbdf8 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -211,15 +211,16 @@ int HRawAnimClass::Load_W3D(ChunkLoadClass & cload) pre30 = true; } - strlcpy(Name, aheader.HierarchyName, ARRAY_SIZE(Name)); + static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); + strcpy(Name, aheader.HierarchyName); strlcat(Name, ".", ARRAY_SIZE(Name)); strlcat(Name, aheader.Name, ARRAY_SIZE(Name)); // TSS chasing crash bug 05/26/99 WWASSERT(HierarchyName != NULL); WWASSERT(aheader.HierarchyName != NULL); - WWASSERT(sizeof(HierarchyName) >= W3D_NAME_LEN); - strlcpy(HierarchyName,aheader.HierarchyName,W3D_NAME_LEN); + static_assert(ARRAY_SIZE(HierarchyName) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); + strcpy(HierarchyName, aheader.HierarchyName); HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName); if (base_pose == NULL) { From 418eef2da668aeb9d18e36eb09737b244344bd5c Mon Sep 17 00:00:00 2001 From: Skyaero <21192585+Skyaero42@users.noreply.github.com> Date: Sat, 22 Nov 2025 19:52:05 +0100 Subject: [PATCH 2/2] removing unnecessary asserts in hrawanim --- Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp | 7 ++----- .../Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp index 5cc6d75dcfb..b4dcf09fe14 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -216,11 +216,8 @@ int HRawAnimClass::Load_W3D(ChunkLoadClass & cload) strlcat(Name, ".", ARRAY_SIZE(Name)); strlcat(Name, aheader.Name, ARRAY_SIZE(Name)); - // TSS chasing crash bug 05/26/99 - WWASSERT(HierarchyName != NULL); - WWASSERT(aheader.HierarchyName != NULL); - static_assert(ARRAY_SIZE(HierarchyName) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); - strcpy(HierarchyName, aheader.HierarchyName); + static_assert(ARRAY_SIZE(HierarchyName) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); + strcpy(HierarchyName, aheader.HierarchyName); HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName); if (base_pose == NULL) { diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp index e6fd62fbdf8..17875705d1b 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -216,11 +216,8 @@ int HRawAnimClass::Load_W3D(ChunkLoadClass & cload) strlcat(Name, ".", ARRAY_SIZE(Name)); strlcat(Name, aheader.Name, ARRAY_SIZE(Name)); - // TSS chasing crash bug 05/26/99 - WWASSERT(HierarchyName != NULL); - WWASSERT(aheader.HierarchyName != NULL); - static_assert(ARRAY_SIZE(HierarchyName) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); - strcpy(HierarchyName, aheader.HierarchyName); + static_assert(ARRAY_SIZE(HierarchyName) >= ARRAY_SIZE(aheader.HierarchyName), "Incorrect array size"); + strcpy(HierarchyName, aheader.HierarchyName); HTreeClass * base_pose = WW3DAssetManager::Get_Instance()->Get_HTree(HierarchyName); if (base_pose == NULL) {