diff --git a/Core/Libraries/Source/WWVegas/WWLib/TARGA.cpp b/Core/Libraries/Source/WWVegas/WWLib/TARGA.cpp index 18fbd16680..de3d8773d1 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 3aca266605..628a9453ac 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 41e5557df0..f65abb69af 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 87b28837ea..27ea79983c 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 d2dfd93862..b4dcf09fe1 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -211,15 +211,13 @@ 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 957fd56bae..182df0ad3f 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 b1de518e71..890eeb4f65 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 e18d2c8eab..2bec94d959 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 488bb4e72a..af10ea6633 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 2a76881dd3..17875705d1 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -211,15 +211,13 @@ 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) {