Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameengine): bound the formatting that takes its text from data
Olcay Seygan24afd12cdb3c
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cppindex 20f464182..a8978a4e8 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp@@ -425,9 +425,13 @@ static UnsignedInt s_framesAccumulated = 0;const double ms = (double)bestTime / s_ticksPerUSec / 1000.0;if (ms < 0.05)break; // nothing left worth naming- if (used > (Int)sizeof(line) - 64)+ // The old guard reserved 64 bytes and hoped the name fitted in them. snprintf says how+ // much it wanted, so a name that does not fit stops the line instead of running past it.+ const Int room = (Int)ARRAY_SIZE(line) - used;+ const Int wrote = snprintf(line + used, room, " %s %.1f", best->m_identifier, ms);+ if (wrote < 0 || wrote >= room)break;- used += sprintf(line + used, " %s %.1f", best->m_identifier, ms);+ used += wrote;}DEBUG_LOG(("%s\n", line));}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cppindex 234ab0802..ad462b895 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp@@ -2743,7 +2743,7 @@ GameWindow *GameWindowManager::winCreateFromScript( AsciiString filenameString,// place for the window files subdirectory//if( strchr( filename, '\\' ) == NULL )- sprintf( filepath, "Window\\%s", filename );+ snprintf( filepath, ARRAY_SIZE(filepath), "Window\\%s", filename );elsestrcpy( filepath, filename );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex c6d60fb87..88f51cabe 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -2392,7 +2392,7 @@ void GameLogic::startNewGame( Bool loadingSaveGame )req.buddyRequestType = BuddyRequest::BUDDYREQUEST_SETSTATUS;req.arg.status.status = GP_PLAYING;strcpy(req.arg.status.statusString, "Playing");- sprintf(req.arg.status.locationString, "%s", WideCharStringToMultiByte(TheGameSpyGame->getGameName().str()).c_str());+ strlcpy(req.arg.status.locationString, WideCharStringToMultiByte(TheGameSpyGame->getGameName().str()).c_str(), ARRAY_SIZE(req.arg.status.locationString));TheGameSpyBuddyMessageQueue->addRequest(req);}@@ -3835,15 +3835,19 @@ static const char *getModuleProfileReport( void )if( theWorstModuleKey == NAMEKEY_INVALID ){- sprintf( report, "%d updates", theModuleUpdateCount );+ snprintf( report, ARRAY_SIZE(report), "%d updates", theModuleUpdateCount );return report;}+ // The names in this line are a module class and a thing template, both of them out of INI, so+ // four of them could be longer than the line. Nothing bounded this before.const Real worstMS = freq ? (Real)( (double)theWorstModuleTicks * 1000.0 / (double)freq ) : 0.0f;- Int used = sprintf( report, "%d updates, worst %s on %s %.1fms", theModuleUpdateCount,+ Int used = snprintf( report, ARRAY_SIZE(report), "%d updates, worst %s on %s %.1fms", theModuleUpdateCount,TheNameKeyGenerator->keyToName( theWorstModuleKey ).str(),theWorstModuleThing ? theWorstModuleThing->getName().str() : "<none>",worstMS );+ if( used < 0 || used >= (Int)ARRAY_SIZE(report) )+ return report;// and the three kinds of module the sweep spent the most time in, whatever the worst one wasfor( Int rank = 0; rank < 3; rank++ )@@ -3857,9 +3861,13 @@ static const char *getModuleProfileReport( void )break;const Real ms = freq ? (Real)( (double)theModuleKindTicks[ best ] * 1000.0 / (double)freq ) : 0.0f;- used += sprintf( report + used, " | %s %dx/%.1f",+ const Int room = (Int)ARRAY_SIZE(report) - used;+ const Int wrote = snprintf( report + used, room, " | %s %dx/%.1f",TheNameKeyGenerator->keyToName( theModuleKindKey[ best ] ).str(),theModuleKindCount[ best ], ms );+ if( wrote < 0 || wrote >= room )+ break;+ used += wrote;theModuleKindTicks[ best ] = -1; // taken; the next pass finds the next one down}diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cppindex de83de0bd..01d63a2f8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp@@ -871,7 +871,7 @@ void GameSpyStagingRoom::launchGame( void )req.buddyRequestType = BuddyRequest::BUDDYREQUEST_SETSTATUS;req.arg.status.status = GP_PLAYING;strcpy(req.arg.status.statusString, "Loading");- sprintf(req.arg.status.locationString, "%s", WideCharStringToMultiByte(TheGameSpyGame->getGameName().str()).c_str());+ strlcpy(req.arg.status.locationString, WideCharStringToMultiByte(TheGameSpyGame->getGameName().str()).c_str(), ARRAY_SIZE(req.arg.status.locationString));TheGameSpyBuddyMessageQueue->addRequest(req);if (TheNAT != NULL) {diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/PeerThread.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/PeerThread.cppindex 40909ac8d..9fb8244ec 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/PeerThread.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/PeerThread.cpp@@ -697,17 +697,17 @@ static void updateBuddyStatus( GameSpyBuddyStatus status, Int groupRoom = 0, stdcase BUDDY_STAGING:req.arg.status.status = GP_STAGING;strcpy(req.arg.status.statusString, "Staging");- sprintf(req.arg.status.locationString, "%s", gameName.c_str());+ strlcpy(req.arg.status.locationString, gameName.c_str(), ARRAY_SIZE(req.arg.status.locationString));break;case BUDDY_LOADING:req.arg.status.status = GP_PLAYING;strcpy(req.arg.status.statusString, "Loading");- sprintf(req.arg.status.locationString, "%s", gameName.c_str());+ strlcpy(req.arg.status.locationString, gameName.c_str(), ARRAY_SIZE(req.arg.status.locationString));break;case BUDDY_PLAYING:req.arg.status.status = GP_PLAYING;strcpy(req.arg.status.statusString, "Playing");- sprintf(req.arg.status.locationString, "%s", gameName.c_str());+ strlcpy(req.arg.status.locationString, gameName.c_str(), ARRAY_SIZE(req.arg.status.locationString));break;case BUDDY_MATCHING:req.arg.status.status = GP_ONLINE;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cppindex de65dc687..50ff0fab5 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp@@ -238,7 +238,7 @@ VideoStreamInterface* BinkVideoPlayer::open( AsciiString movieTitle )if (TheGlobalData->m_modDir.isNotEmpty()){char filePath[ _MAX_PATH ];- sprintf( filePath, "%s%s\\%s.%s", TheGlobalData->m_modDir.str(), VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );+ snprintf( filePath, ARRAY_SIZE(filePath), "%s%s\\%s.%s", TheGlobalData->m_modDir.str(), VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );HBINK handle = BinkOpen(filePath , BINKPRELOADALL );DEBUG_ASSERTLOG(!handle, ("opened bink file %s\n", filePath));if (handle)@@ -254,7 +254,7 @@ VideoStreamInterface* BinkVideoPlayer::open( AsciiString movieTitle )if (!handle){char filePath[ _MAX_PATH ];- sprintf( filePath, "%s\\%s.%s", VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );+ snprintf( filePath, ARRAY_SIZE(filePath), "%s\\%s.%s", VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );handle = BinkOpen(filePath , BINKPRELOADALL );DEBUG_ASSERTLOG(!handle, ("opened bink file %s\n", localizedFilePath));}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cppindex f4fdb5e99..a42cb770a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp@@ -767,12 +767,12 @@ void ModelConditionInfo::validateWeaponBarrelInfo() constif (!recoilBoneName.isEmpty()){- sprintf(buffer, "%s%02d", recoilBoneName.str(), i);+ snprintf(buffer, ARRAY_SIZE(buffer), "%s%02d",recoilBoneName.str(), i);findPristineBone(NAMEKEY(buffer), &info.m_recoilBone);}if (!mfName.isEmpty()){- sprintf(buffer, "%s%02d", mfName.str(), i);+ snprintf(buffer, ARRAY_SIZE(buffer), "%s%02d",mfName.str(), i);findPristineBone(NAMEKEY(buffer), &info.m_muzzleFlashBone);#if defined(_DEBUG) || defined(_INTERNAL)if (info.m_muzzleFlashBone)@@ -781,7 +781,7 @@ void ModelConditionInfo::validateWeaponBarrelInfo() const}if (!fxBoneName.isEmpty()){- sprintf(buffer, "%s%02d", fxBoneName.str(), i);+ snprintf(buffer, ARRAY_SIZE(buffer), "%s%02d",fxBoneName.str(), i);findPristineBone(NAMEKEY(buffer), &info.m_fxBone);// special case: if we have multiple muzzleflashes, but only one fxbone, use that fxbone for everything.if (info.m_fxBone == 0 && info.m_muzzleFlashBone != 0)@@ -791,7 +791,7 @@ void ModelConditionInfo::validateWeaponBarrelInfo() constInt plbBoneIndex = 0;if (!plbName.isEmpty()){- sprintf(buffer, "%s%02d", plbName.str(), i);+ snprintf(buffer, ARRAY_SIZE(buffer), "%s%02d",plbName.str(), i);const Matrix3D* mtx = findPristineBone(NAMEKEY(buffer), &plbBoneIndex);if (mtx != NULL)info.m_projectileOffsetMtx = *mtx;@@ -3651,7 +3651,7 @@ Int W3DModelDraw::getPristineBonePositionsForConditionState(if (i == 0)strcpy(buffer, boneNamePrefix);else- sprintf(buffer, "%s%02d", boneNamePrefix, i);+ snprintf(buffer, ARRAY_SIZE(buffer), "%s%02d", boneNamePrefix, i);for (char *c = buffer; c && *c; ++c){@@ -3808,7 +3808,7 @@ Int W3DModelDraw::getCurrentBonePositions(if (i == 0)strcpy(buffer, boneNamePrefix);else- sprintf(buffer, "%s%02d", boneNamePrefix, i);+ snprintf(buffer, ARRAY_SIZE(buffer), "%s%02d", boneNamePrefix, i);Int boneIndex = m_renderObject->Get_Bone_Index(buffer);if (boneIndex == 0)diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DSupplyDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DSupplyDraw.cppindex c50a3bd63..d479ab13e 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DSupplyDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DSupplyDraw.cpp@@ -96,7 +96,7 @@ void W3DSupplyDraw::updateDrawModuleSupplyStatus( Int maxSupply, Int currentSuppwhile( currentIndex <= highIndex ){char buffer[16];- sprintf( buffer, "%s%02d", boneName.str(), currentIndex );+ snprintf( buffer, ARRAY_SIZE(buffer), "%s%02d", boneName.str(), currentIndex );ModelConditionInfo::HideShowSubObjInfo info;info.hide = hide;info.subObjName = buffer;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cppindex 81ab8d0d4..6a924b88f 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp@@ -44,6 +44,7 @@* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */#include <always.h>+#include "stringex.h"#include "W3DDevice/GameClient/W3DAssetManager.h"#include "proto.h"#include "rendobj.h"@@ -280,25 +281,29 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj(const char* name)//---------------------------------------------------------------------/** 'Generals' specific munging to encode team color and scale in model name */+// Every caller of the four Munge helpers below hands them a buffer of this size, and the helpers+// write straight into it, so the number lives in one place rather than six.+enum { MUNGED_NAME_SIZE = 512 };+static inline void Munge_Render_Obj_Name(char *newname, const char *oldname, float scale, const int color, const char *textureName){char lower_case_name[255];- strcpy(lower_case_name, oldname);+ strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name));_strlwr(lower_case_name);if (!textureName)textureName = "";- sprintf(newname,"#%d!%g!%s#%s",color,scale,textureName,lower_case_name);+ snprintf(newname, MUNGED_NAME_SIZE, "#%d!%g!%s#%s",color,scale,textureName,lower_case_name);}//---------------------------------------------------------------------static inline void Munge_Texture_Name(char *newname, const char *oldname, const int color){char lower_case_name[255];- strcpy(lower_case_name, oldname);+ strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name));_strlwr(lower_case_name);- sprintf(newname,"#%d#%s", color, lower_case_name);+ snprintf(newname, MUNGED_NAME_SIZE, "#%d#%s", color, lower_case_name);}//---------------------------------------------------------------------@@ -380,7 +385,7 @@ int W3DAssetManager::replacePrototypeTexture(RenderObjClass *robj, const char **/TextureClass * W3DAssetManager::Find_Texture(const char * name, const int color){- char newname[512];+ char newname[MUNGED_NAME_SIZE];Munge_Texture_Name(newname, name, color);// see if we have a cached copy@@ -702,7 +707,7 @@ TextureClass * W3DAssetManager::Recolor_Texture_One_Time(TextureClass *texture,newtex->Get_Filter().Set_U_Addr_Mode(texture->Get_Filter().Get_U_Addr_Mode());newtex->Get_Filter().Set_V_Addr_Mode(texture->Get_Filter().Get_V_Addr_Mode());- char newname[512];+ char newname[MUNGED_NAME_SIZE];Munge_Texture_Name(newname, name, color);newtex->Set_Texture_Name(newname);@@ -756,7 +761,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj(return robj;}- char newname[512];+ char newname[MUNGED_NAME_SIZE];Munge_Render_Obj_Name(newname, name, scale, color, newTexture);// see if we got a cached version@@ -813,7 +818,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj(#endif::lstrcat(filename, ".w3d");} else {- sprintf( filename, "%s.w3d", name);+ snprintf( filename, ARRAY_SIZE(filename), "%s.w3d", name);}// If we can't find it, try the parent directory@@ -1436,17 +1441,17 @@ void W3DAssetManager::Make_Unique(RenderObjClass *robj, Bool geometry, Bool colostatic inline void Munge_Render_Obj_Name(char *newname, const char *oldname, float scale, const Vector3 &hsv_shift){char lower_case_name[255];- strcpy(lower_case_name, oldname);+ strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name));_strlwr(lower_case_name);- sprintf(newname,"#%s!%gH%gS%gV%g", lower_case_name, scale, hsv_shift.X, hsv_shift.Y, hsv_shift.Z);+ snprintf(newname, MUNGED_NAME_SIZE, "#%s!%gH%gS%gV%g", lower_case_name, scale, hsv_shift.X, hsv_shift.Y, hsv_shift.Z);}static inline void Munge_Texture_Name(char *newname, const char *oldname, const Vector3 &hsv_shift){char lower_case_name[255];- strcpy(lower_case_name, oldname);+ strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name));_strlwr(lower_case_name);- sprintf(newname,"#%s!H%gS%gV%g", lower_case_name, hsv_shift.X, hsv_shift.Y, hsv_shift.Z);+ snprintf(newname, MUNGED_NAME_SIZE, "#%s!H%gS%gV%g", lower_case_name, hsv_shift.X, hsv_shift.Y, hsv_shift.Z);}RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scale, const Vector3 &hsv_shift)@@ -1464,7 +1469,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scal// base case, no scale or hue shiftingif (!reallyscale && !reallyhsv_shift) return WW3DAssetManager::Create_Render_Obj(name);- char newname[512];+ char newname[MUNGED_NAME_SIZE];Munge_Render_Obj_Name(newname, name, scale, hsv_shift);// see if we got a cached version@@ -1504,7 +1509,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scalelse::lstrcat (filename, ".w3d");} else {- sprintf( filename, "%s.w3d", name);+ snprintf( filename, ARRAY_SIZE(filename), "%s.w3d", name);}// If we can't find it, try the parent directory@@ -1684,7 +1689,7 @@ TextureClass * W3DAssetManager::Recolor_Texture_One_Time(TextureClass *texture,newtex->Set_U_Addr_Mode(texture->Get_U_Addr_Mode());newtex->Set_V_Addr_Mode(texture->Get_V_Addr_Mode());- char newname[512];+ char newname[MUNGED_NAME_SIZE];Munge_Texture_Name(newname, name, hsv_shift);newtex->Set_Texture_Name(newname);@@ -1699,7 +1704,7 @@ TextureClass * W3DAssetManager::Recolor_Texture_One_Time(TextureClass *texture,TextureClass * W3DAssetManager::Find_Texture(const char * name, const Vector3 &hsv_shift){- char newname[512];+ char newname[MUNGED_NAME_SIZE];Munge_Texture_Name(newname, name, hsv_shift);// see if we have a cached copydiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 959b9a19c..d87dc3509 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -918,7 +918,7 @@ static const Image *loadOrderCursorImage( Mouse::MouseCursor cursor, ICoord2D *hreturn NULL;char path[ 256 ];- sprintf( path, "data\\cursors\\%s.ANI", name.str() );+ snprintf( path, ARRAY_SIZE(path), "data\\cursors\\%s.ANI", name.str() );HCURSOR hcursor = LoadCursorFromFile( path );if( hcursor == NULL )diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cppindex 1f9c2fafb..699452046 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp@@ -196,7 +196,7 @@ Bool W3DMouse::loadD3DCursorTextures(MouseCursor cursor)if (animFrames == 1){ //single animation frame without trailing numbers- sprintf(FrameName,"%s.tga",baseName);+ snprintf(FrameName, ARRAY_SIZE(FrameName), "%s.tga",baseName);cursorTextures[cursor][0]= am->Get_Texture(FrameName);m_currentD3DSurface[0]=cursorTextures[cursor][0]->Get_Surface_Level();m_currentFrames = 1;@@ -204,7 +204,7 @@ Bool W3DMouse::loadD3DCursorTextures(MouseCursor cursor)elsefor (Int i=0; i<animFrames; i++){- sprintf(FrameName,"%s%04d.tga",baseName,i);+ snprintf(FrameName, ARRAY_SIZE(FrameName), "%s%04d.tga",baseName,i);if ((cursorTextures[cursor][i]=am->Get_Texture(FrameName)) != NULL){ m_currentD3DSurface[m_currentFrames]=cursorTextures[cursor][i]->Get_Surface_Level();m_currentFrames++;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cppindex cd526401e..61e2d3c8e 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp@@ -507,10 +507,10 @@ void W3DTreeBuffer::updateTexture(void)for (i=0; i<m_numTreeTypes; i++) {char texturePath[ _MAX_PATH ];m_treeTypes[i].m_numTiles = 0;- sprintf( texturePath, "%s%s", TERRAIN_TGA_DIR_PATH, m_treeTypes[i].m_data->m_textureName.str() );+ snprintf( texturePath, ARRAY_SIZE(texturePath), "%s%s",TERRAIN_TGA_DIR_PATH, m_treeTypes[i].m_data->m_textureName.str() );theFile = TheFileSystem->openFile( texturePath, File::READ|File::BINARY);if (theFile==NULL) {- sprintf( texturePath, "%s%s", TGA_DIR_PATH, m_treeTypes[i].m_data->m_textureName.str() );+ snprintf( texturePath, ARRAY_SIZE(texturePath), "%s%s",TGA_DIR_PATH, m_treeTypes[i].m_data->m_textureName.str() );theFile = TheFileSystem->openFile( texturePath, File::READ|File::BINARY);}if (theFile != NULL) {diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cppindex 5f1b2c213..edfb980bf 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp@@ -1043,7 +1043,7 @@ void WorldHeightMap::readTexClass(TXTextureClass *texClass, TileData **tileData)}else{- sprintf( texturePath, "%s%s", TERRAIN_TGA_DIR_PATH, terrain->getTexture().str() );+ snprintf( texturePath, ARRAY_SIZE(texturePath), "%s%s", TERRAIN_TGA_DIR_PATH, terrain->getTexture().str() );theFile = TheFileSystem->openFile( texturePath, File::READ|File::BINARY);}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cppindex 2dd22b14d..c8c395a95 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32Mouse.cpp@@ -416,9 +416,9 @@ void Win32Mouse::initCursorResources(void)char resourcePath[256];//Check if this is a directional cursorif (m_cursorInfo[cursor].numDirections > 1)- sprintf(resourcePath,"data\\cursors\\%s%d.ANI",m_cursorInfo[cursor].textureName.str(),direction);+ snprintf(resourcePath, ARRAY_SIZE(resourcePath), "data\\cursors\\%s%d.ANI",m_cursorInfo[cursor].textureName.str(),direction);else- sprintf(resourcePath,"data\\cursors\\%s.ANI",m_cursorInfo[cursor].textureName.str());+ snprintf(resourcePath, ARRAY_SIZE(resourcePath), "data\\cursors\\%s.ANI",m_cursorInfo[cursor].textureName.str());cursorResources[cursor][direction]=LoadCursorFromFile(resourcePath);DEBUG_ASSERTCRASH(cursorResources[cursor][direction], ("MissingCursor %s\n",resourcePath));diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cppindex 76081ccac..a1ceb6963 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/Except.cpp@@ -455,7 +455,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)** For access violations, print out the violation address and if it was read or write.*/if (e_info->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {- sprintf(scrap, "Access address:%08X ", access_address);+ snprintf(scrap, ARRAY_SIZE(scrap), "Access address:%08X ", access_address);Add_Txt(scrap);if (access_read_write) {Add_Txt("was written to.\r\n");@@ -477,13 +477,13 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)if (!IsBadCodePtr((FARPROC)context->Eip)) {if (_SymGetSymFromAddr != NULL && _SymGetSymFromAddr (GetCurrentProcess(), context->Eip, &displacement, symptr)) {- sprintf (scrap, "Exception occurred at %08X - %s + %08X\r\n", context->Eip, symptr->Name, displacement);+ snprintf (scrap, ARRAY_SIZE(scrap), "Exception occurred at %08X - %s + %08X\r\n", context->Eip, symptr->Name, displacement);} else {DebugString ("Exception Handler: Failed to get symbol for EIP\r\n");if (_SymGetSymFromAddr != NULL) {DebugString ("Exception Handler: SymGetSymFromAddr failed with code %d - %s\n", GetLastError(), Last_Error_Text());}- sprintf (scrap, "Exception occurred at %08X\r\n", context->Eip);+ snprintf (scrap, ARRAY_SIZE(scrap), "Exception occurred at %08X\r\n", context->Eip);}} else {DebugString ("Exception Handler: context->Eip is bad code pointer\n");@@ -517,12 +517,12 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)if (_SymGetSymFromAddr != NULL && _SymGetSymFromAddr (GetCurrentProcess(), temp_addr, &displacement, symptr)) {char symbuf[256];- sprintf(symbuf, "%s + %08X\r\n", symptr->Name, displacement);+ snprintf(symbuf, ARRAY_SIZE(symbuf), "%s + %08X\r\n", symptr->Name, displacement);Add_Txt(symbuf);}} else {char symbuf[256];- sprintf(symbuf, "%08x\r\n", temp_addr);+ snprintf(symbuf, ARRAY_SIZE(symbuf), "%08x\r\n", temp_addr);Add_Txt(symbuf);}}@@ -538,10 +538,10 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)/*** Add in the version info.*/- sprintf(scrap, "\r\nVersion %s\r\n", Version_Name());+ snprintf(scrap, ARRAY_SIZE(scrap), "\r\nVersion %s\r\n", Version_Name());Add_Txt(scrap);- sprintf(scrap, "Internal Version %s\r\n", VerNum.Version_Name());+ snprintf(scrap, ARRAY_SIZE(scrap), "Internal Version %s\r\n", VerNum.Version_Name());Add_Txt(scrap);char buildinfo[128];@@ -554,7 +554,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)#endif //(0)if (AppVersionCallback) {- sprintf(scrap, "%s\r\n\r\n", AppVersionCallback());+ snprintf(scrap, ARRAY_SIZE(scrap), "%s\r\n\r\n", AppVersionCallback());Add_Txt(scrap);}@@ -567,7 +567,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)** Get the thread info from ThreadClass.*/for (int thread = 0 ; thread < ThreadList.Count() ; thread++) {- sprintf(scrap, " ID: %08X - %s", ThreadList[thread]->ThreadID, ThreadList[thread]->ThreadName);+ snprintf(scrap, ARRAY_SIZE(scrap), " ID: %08X - %s", ThreadList[thread]->ThreadID, ThreadList[thread]->ThreadName);Add_Txt(scrap);if (GetCurrentThreadId() == ThreadList[thread]->ThreadID) {Add_Txt(" ***CURRENT THREAD***");@@ -578,7 +578,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)/*** CPU type*/- sprintf(scrap, "\r\nCPU %s, %d Mhz, Vendor: %s\r\n", (char*)CPUDetectClass::Get_Processor_String(), Get_RDTSC_CPU_Speed(), (char*)CPUDetectClass::Get_Processor_Manufacturer_Name());+ snprintf(scrap, ARRAY_SIZE(scrap), "\r\nCPU %s, %d Mhz, Vendor: %s\r\n", (char*)CPUDetectClass::Get_Processor_String(), Get_RDTSC_CPU_Speed(), (char*)CPUDetectClass::Get_Processor_Manufacturer_Name());Add_Txt(scrap);@@ -589,15 +589,15 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)/*** Dump the registers.*/- sprintf(scrap, "Eip:%08X\tEsp:%08X\tEbp:%08X\r\n", context->Eip, context->Esp, context->Ebp);+ snprintf(scrap, ARRAY_SIZE(scrap), "Eip:%08X\tEsp:%08X\tEbp:%08X\r\n", context->Eip, context->Esp, context->Ebp);Add_Txt(scrap);- sprintf(scrap, "Eax:%08X\tEbx:%08X\tEcx:%08X\r\n", context->Eax, context->Ebx, context->Ecx);+ snprintf(scrap, ARRAY_SIZE(scrap), "Eax:%08X\tEbx:%08X\tEcx:%08X\r\n", context->Eax, context->Ebx, context->Ecx);Add_Txt(scrap);- sprintf(scrap, "Edx:%08X\tEsi:%08X\tEdi:%08X\r\n", context->Edx, context->Esi, context->Edi);+ snprintf(scrap, ARRAY_SIZE(scrap), "Edx:%08X\tEsi:%08X\tEdi:%08X\r\n", context->Edx, context->Esi, context->Edi);Add_Txt(scrap);- sprintf(scrap, "EFlags:%08X \r\n", context->EFlags);+ snprintf(scrap, ARRAY_SIZE(scrap), "EFlags:%08X \r\n", context->EFlags);Add_Txt(scrap);- sprintf(scrap, "CS:%04x SS:%04x DS:%04x ES:%04x FS:%04x GS:%04x\r\n", context->SegCs, context->SegSs, context->SegDs, context->SegEs, context->SegFs, context->SegGs);+ snprintf(scrap, ARRAY_SIZE(scrap), "CS:%04x SS:%04x DS:%04x ES:%04x FS:%04x GS:%04x\r\n", context->SegCs, context->SegSs, context->SegDs, context->SegEs, context->SegFs, context->SegGs);Add_Txt(scrap);@@ -605,28 +605,28 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)** Now the FP registers.*/Add_Txt("\r\nFloating point status\r\n");- sprintf(scrap, " Control word: %08x\r\n", context->FloatSave.ControlWord);+ snprintf(scrap, ARRAY_SIZE(scrap), " Control word: %08x\r\n", context->FloatSave.ControlWord);Add_Txt(scrap);- sprintf(scrap, " Status word: %08x\r\n", context->FloatSave.StatusWord);+ snprintf(scrap, ARRAY_SIZE(scrap), " Status word: %08x\r\n", context->FloatSave.StatusWord);Add_Txt(scrap);- sprintf(scrap, " Tag word: %08x\r\n", context->FloatSave.TagWord);+ snprintf(scrap, ARRAY_SIZE(scrap), " Tag word: %08x\r\n", context->FloatSave.TagWord);Add_Txt(scrap);- sprintf(scrap, " Error Offset: %08x\r\n", context->FloatSave.ErrorOffset);+ snprintf(scrap, ARRAY_SIZE(scrap), " Error Offset: %08x\r\n", context->FloatSave.ErrorOffset);Add_Txt(scrap);- sprintf(scrap, " Error Selector: %08x\r\n", context->FloatSave.ErrorSelector);+ snprintf(scrap, ARRAY_SIZE(scrap), " Error Selector: %08x\r\n", context->FloatSave.ErrorSelector);Add_Txt(scrap);- sprintf(scrap, " Data Offset: %08x\r\n", context->FloatSave.DataOffset);+ snprintf(scrap, ARRAY_SIZE(scrap), " Data Offset: %08x\r\n", context->FloatSave.DataOffset);Add_Txt(scrap);- sprintf(scrap, " Data Selector: %08x\r\n", context->FloatSave.DataSelector);+ snprintf(scrap, ARRAY_SIZE(scrap), " Data Selector: %08x\r\n", context->FloatSave.DataSelector);Add_Txt(scrap);- sprintf(scrap, " Cr0NpxState: %08x\r\n", context->FloatSave.Spare0); // SDK renamed Cr0NpxState -> Spare0+ snprintf(scrap, ARRAY_SIZE(scrap), " Cr0NpxState: %08x\r\n", context->FloatSave.Spare0); // SDK renamed Cr0NpxState -> Spare0Add_Txt(scrap);for (int fp=0 ; fp<SIZE_OF_80387_REGISTERS / 10 ; fp++) {- sprintf(scrap, "ST%d : ", fp);+ snprintf(scrap, ARRAY_SIZE(scrap), "ST%d : ", fp);Add_Txt(scrap);for (int b=0 ; b<10 ; b++) {- sprintf(scrap, "%02X", context->FloatSave.RegisterArea[(fp*10) + b]);+ snprintf(scrap, ARRAY_SIZE(scrap), "%02X", context->FloatSave.RegisterArea[(fp*10) + b]);Add_Txt(scrap);}@@ -643,7 +643,7 @@ void Dump_Exception_Info(EXCEPTION_POINTERS *e_info)fstp qword ptr [fp_value]pop eax}- sprintf(scrap, " %+#.17e\r\n", fp_value);+ snprintf(scrap, ARRAY_SIZE(scrap), " %+#.17e\r\n", fp_value);Add_Txt(scrap);}