From 3069fba05d86bc5968e6db88baef1e223ed9e079 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Mon, 20 Oct 2025 22:23:39 +0200 Subject: [PATCH 1/4] bugfix: Fix global-buffer-overflow in WorldBuilder (MapObjectProps class) --- .../Code/Tools/WorldBuilder/include/StdAfx.h | 2 +- .../Tools/WorldBuilder/src/BaseBuildProps.cpp | 2 +- .../Tools/WorldBuilder/src/BlendMaterial.cpp | 2 +- .../Code/Tools/WorldBuilder/src/BuildList.cpp | 12 ++++---- .../Tools/WorldBuilder/src/EditParameter.cpp | 2 +- .../Tools/WorldBuilder/src/FeatherOptions.cpp | 2 +- .../Tools/WorldBuilder/src/GroveOptions.cpp | 14 ++++----- .../Tools/WorldBuilder/src/LayersList.cpp | 2 +- .../WorldBuilder/src/MeshMoldOptions.cpp | 12 ++++---- .../Tools/WorldBuilder/src/MoundOptions.cpp | 10 +++---- .../Code/Tools/WorldBuilder/src/SaveMap.cpp | 2 +- .../WorldBuilder/src/TeamObjectProperties.cpp | 10 +++---- .../WorldBuilder/src/TerrainMaterial.cpp | 4 +-- .../Tools/WorldBuilder/src/WHeightMapEdit.cpp | 2 +- .../Tools/WorldBuilder/src/WaterOptions.cpp | 12 ++++---- .../Tools/WorldBuilder/src/WorldBuilder.cpp | 2 +- .../Tools/WorldBuilder/src/brushoptions.cpp | 10 +++---- .../Tools/WorldBuilder/src/mapobjectprops.cpp | 30 +++++++++---------- .../Tools/WorldBuilder/src/playerlistdlg.cpp | 4 +-- .../Code/Tools/WorldBuilder/src/wbview3d.cpp | 2 +- 20 files changed, 69 insertions(+), 69 deletions(-) diff --git a/GeneralsMD/Code/Tools/WorldBuilder/include/StdAfx.h b/GeneralsMD/Code/Tools/WorldBuilder/include/StdAfx.h index be0f37ede0..a13dba31c5 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/include/StdAfx.h +++ b/GeneralsMD/Code/Tools/WorldBuilder/include/StdAfx.h @@ -42,7 +42,7 @@ #include // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT - +#include //{{AFX_INSERT_LOCATION}} diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp index c2ecf3c809..31f7891263 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp @@ -66,7 +66,7 @@ BOOL BaseBuildProps::OnInitDialog() // add health CWnd* pHealth = GetDlgItem(IDC_MAPOBJECT_StartingHealthEdit); static char buff[12]; - sprintf(buff, "%d", m_health); + snprintf(buff, ARRAY_SIZE(buff), "%d", m_health); pHealth->SetWindowText(buff); CButton* pItem; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp index e8ea32a206..2db5faf7b9 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp @@ -208,7 +208,7 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare // Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles; char label[_MAX_PATH]; - sprintf(label, "%s", buffer); + snprintf(label, ARRAY_SIZE(label), "%s", buffer); if( doAdd ) diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp index 3c9034a89a..773687461d 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -449,16 +449,16 @@ void BuildList::OnSelchangeBuildList() PointerTool::clearSelection(); // unselect other stuff. if (pBuildInfo) { CWnd *edit; - static char buff[12]; + static char buff[64]; pBuildInfo->setSelected(true); m_angle = pBuildInfo->getAngle() * 180/PI; - sprintf(buff, "%0.2f", m_angle); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); m_height = pBuildInfo->getLocation()->z; - sprintf(buff, "%0.2f", m_height); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height); edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); @@ -638,11 +638,11 @@ void BuildList::PopSliderChanged(const long sliderID, long theVal) { // CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); CWnd* edit; - static char buff[12]; + static char buff[64]; switch (sliderID) { case IDC_HEIGHT_POPUP: m_height = theVal; - sprintf(buff, "%0.2f", m_height); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height); edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); OnChangeZOffset(); @@ -650,7 +650,7 @@ void BuildList::PopSliderChanged(const long sliderID, long theVal) case IDC_ANGLE_POPUP: m_angle = theVal; - sprintf(buff, "%0.2f", m_angle); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); break; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/EditParameter.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/EditParameter.cpp index bd2dc55f5c..94fb3dad93 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/EditParameter.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/EditParameter.cpp @@ -1368,7 +1368,7 @@ void EditParameter::readFontFile( const char *filename ) { char buffer[ 1024 ]; - sprintf( buffer, "Warning: The font '%s' Size: '%d' Bold: '%d', specified in the config file could not be loaded. Does that font exist?", + snprintf( buffer, ARRAY_SIZE(buffer), "Warning: The font '%s' Size: '%d' Bold: '%d', specified in the config file could not be loaded. Does that font exist?", fontBuffer, size, bold ); //MessageBox( m_appHWnd, buffer, "Cannot Load Font", MB_OK ); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/FeatherOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/FeatherOptions.cpp index 831e11d053..806d74b602 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/FeatherOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/FeatherOptions.cpp @@ -134,7 +134,7 @@ void FeatherOptions::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentFeather = width; FeatherTool::setFeather(m_currentFeather); - sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/GroveOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/GroveOptions.cpp index 22aca167ae..7be64efb17 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/GroveOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/GroveOptions.cpp @@ -266,35 +266,35 @@ void GroveOptions::_setDefaultRatios(void) CWnd* pWnd = GetDlgItem(IDC_Grove_Per1); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio1", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per2); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio2", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per3); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio3", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per4); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio4", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per5); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio5", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } } @@ -308,7 +308,7 @@ void GroveOptions::_setDefaultNumTrees(void) int defaultNumTrees = AfxGetApp()->GetProfileInt("GroveOptions", "NumberofTrees", 10); static char buff[ARBITRARY_BUFF_SIZE]; - sprintf(buff, "%d", defaultNumTrees); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultNumTrees); pWnd->SetWindowText(buff); } @@ -379,7 +379,7 @@ void GroveOptions::_updateTreeWeights(void) pWnd = GetDlgItem(IDC_Grove_PerTotal); if (pWnd) { - sprintf(buff, "%d", val); + snprintf(buff, ARRAY_SIZE(buff), "%d", val); pWnd->SetWindowText(buff); } } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/LayersList.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/LayersList.cpp index 88d94102d0..bc30af05a1 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/LayersList.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/LayersList.cpp @@ -828,7 +828,7 @@ void LayersList::OnNewLayer() } static char buffer[1024]; - sprintf(buffer, "%s %d", TheDefaultNewLayerName.c_str(), newLayerNum); + snprintf(buffer, ARRAY_SIZE(buffer), "%s %d", TheDefaultNewLayerName.c_str(), newLayerNum); addLayerNamed(buffer); HTREEITEM newItem = pTree->InsertItem(buffer, 0, 0); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp index 666f1d655a..a742e5841c 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp @@ -148,8 +148,8 @@ BOOL MeshMoldOptions::OnInitDialog() void MeshMoldOptions::setHeight(Real height) { - char buffer[50]; - sprintf(buffer, "%.2f", height); + char buffer[64]; + snprintf(buffer, ARRAY_SIZE(buffer), "%.2f", height); m_currentHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -160,8 +160,8 @@ void MeshMoldOptions::setHeight(Real height) void MeshMoldOptions::setScale(Real scale) { - char buffer[50]; - sprintf(buffer, "%d", (int)floor(scale*100)); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", (int)floor(scale*100)); m_currentScale = scale; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_SCALE_EDIT); @@ -172,8 +172,8 @@ void MeshMoldOptions::setScale(Real scale) void MeshMoldOptions::setAngle(Int angle) { - char buffer[50]; - sprintf(buffer, "%d", angle); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", angle); m_currentAngle = angle; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_ANGLE_EDIT); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/MoundOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/MoundOptions.cpp index f3f1eb9849..daf3d40e10 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/MoundOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/MoundOptions.cpp @@ -78,8 +78,8 @@ void MoundOptions::setWidth(Int width) void MoundOptions::setHeight(Int height) { - char buffer[50]; - sprintf(buffer, "%d", height); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", height); m_currentHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -129,7 +129,7 @@ void MoundOptions::OnChangeFeatherEdit() if (1==sscanf(buffer, "%d", &feather)) { m_currentFeather = feather; MoundTool::setFeather(m_currentFeather); - sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -152,7 +152,7 @@ void MoundOptions::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentWidth = width; MoundTool::setWidth(m_currentWidth); - sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -175,7 +175,7 @@ void MoundOptions::OnChangeHeightEdit() if (1==sscanf(buffer, "%d", &height)) { m_currentHeight = height; MoundTool::setMoundHeight(m_currentHeight); - sprintf(buffer, "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp index f7b18a277b..99c10f930b 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp @@ -128,7 +128,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) if (systemMaps) strcpy(dirBuf, ".\\Maps\\"); else - sprintf(dirBuf, "%sMaps\\", TheGlobalData->getPath_UserData().str()); + snprintf(dirBuf, ARRAY_SIZE(dirBuf), "%sMaps\\", TheGlobalData->getPath_UserData().str()); int len = strlen(dirBuf); if (len > 0 && dirBuf[len - 1] != '\\') { diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/TeamObjectProperties.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/TeamObjectProperties.cpp index 6c707a228f..4f11bd2674 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/TeamObjectProperties.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/TeamObjectProperties.cpp @@ -146,7 +146,7 @@ void TeamObjectProperties::_DictToHealth(void) } else { pItem->SelectString(-1, "Other"); static char buff[12]; - sprintf(buff, "%d", value); + snprintf(buff, ARRAY_SIZE(buff), "%d", value); pItem2->SetWindowText(buff); pItem2->EnableWindow(TRUE); } @@ -270,7 +270,7 @@ void TeamObjectProperties::_DictToVisibilityRange(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_VisionDistance); if (pItem) { static char buff[12]; - sprintf(buff, "%d", distance); + snprintf(buff, ARRAY_SIZE(buff), "%d", distance); if (distance == 0) { pItem->SetWindowText(""); } else { @@ -332,7 +332,7 @@ void TeamObjectProperties::_DictToShroudClearingDistance(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_ShroudClearingDistance); if (pItem) { static char buff[12]; - sprintf(buff, "%d", distance); + snprintf(buff, ARRAY_SIZE(buff), "%d", distance); if (distance == 0) { pItem->SetWindowText(""); } else { @@ -379,8 +379,8 @@ void TeamObjectProperties::_DictToStoppingDistance(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_StoppingDistance); if (pItem) { - static char buff[12]; - sprintf(buff, "%g", stoppingDistance); + static char buff[64]; + sprintf(buff, ARRAY_SIZE(buff), "%g", stoppingDistance); if (stoppingDistance == 0) { pItem->SetWindowText(""); } else { diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp index 69299bc306..6d356be196 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp @@ -336,7 +336,7 @@ void TerrainMaterial::addTerrain(char *pPath, Int terrainNdx, HTREEITEM parent) Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles; char label[_MAX_PATH]; - sprintf(label, "%d%% %s", percent, buffer); + snprintf(label, ARRAY_SIZE(label), "%d%% %s", percent, buffer); if( doAdd ) @@ -405,7 +405,7 @@ void TerrainMaterial::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentWidth = width; BigTileTool::setWidth(m_currentWidth); - sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 586e8f8af6..e81bf7af7d 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -457,7 +457,7 @@ void WorldHeightMapEdit::loadImagesFromTerrainType( TerrainType *terrain ) char buffer[ _MAX_PATH ]; // build path to texture file - sprintf( buffer, "%s%s", TERRAIN_TGA_DIR_PATH, terrain->getTexture().str() ); + snprintf( buffer, ARRAY_SIZE(buffer), "%s%s", TERRAIN_TGA_DIR_PATH, terrain->getTexture().str() ); // create ascii string for texture path AsciiString texturePath( buffer ); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WaterOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WaterOptions.cpp index ef8bb5f754..d69fce7bd9 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WaterOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WaterOptions.cpp @@ -61,8 +61,8 @@ void WaterOptions::DoDataExchange(CDataExchange* pDX) void WaterOptions::setHeight(Int height) { - char buffer[50]; - sprintf(buffer, "%d", height); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", height); m_waterHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -91,9 +91,9 @@ void WaterOptions::updateTheUI(void) pButton->EnableWindow(theTrigger!=NULL); pWnd = m_staticThis->GetDlgItem(IDC_SPACING); - char buffer[_MAX_PATH]; + char buffer[12]; if (pWnd) { - sprintf(buffer, "%d", m_waterPointSpacing); + snprintf(buffer, ARRAY_SIZE(buffer), "%d", m_waterPointSpacing); pWnd->SetWindowText(buffer); } } @@ -492,7 +492,7 @@ void WaterOptions::OnChangeSpacingEdit() { if (m_updating) return; CWnd *pEdit = m_staticThis->GetDlgItem(IDC_SPACING); - char buffer[_MAX_PATH]; + char buffer[12]; if (pEdit) { pEdit->GetWindowText(buffer, sizeof(buffer)); Int height; @@ -500,7 +500,7 @@ void WaterOptions::OnChangeSpacingEdit() if (1==sscanf(buffer, "%d", &height)) { m_waterPointSpacing = height; } else { - sprintf(buffer, "%d", m_waterPointSpacing); + snprintf(buffer, ARRAY_SIZE(buffer), "%d", m_waterPointSpacing); pEdit->SetWindowText(buffer); } m_updating = false; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp index 0acb59714f..2a81f78d5c 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp @@ -376,7 +376,7 @@ BOOL CWorldBuilderApp::InitInstance() strcpy((char*)m_pszProfileName, buf); // ensure the user maps dir exists - sprintf(buf, "%sMaps\\", TheGlobalData->getPath_UserData().str()); + snprintf(buf, ARRAY_SIZE(buf), "%sMaps\\", TheGlobalData->getPath_UserData().str()); CreateDirectory(buf, NULL); // read the water settings from INI (must do prior to initing GameClient, apparently) diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/brushoptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/brushoptions.cpp index c5c73a5490..f8c50586f1 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/brushoptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/brushoptions.cpp @@ -78,8 +78,8 @@ void BrushOptions::setWidth(Int width) void BrushOptions::setHeight(Int height) { - char buffer[50]; - sprintf(buffer, "%d", height); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", height); m_currentHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -129,7 +129,7 @@ void BrushOptions::OnChangeFeatherEdit() if (1==sscanf(buffer, "%d", &feather)) { m_currentFeather = feather; BrushTool::setFeather(m_currentFeather); - sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -152,7 +152,7 @@ void BrushOptions::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentWidth = width; BrushTool::setWidth(m_currentWidth); - sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -175,7 +175,7 @@ void BrushOptions::OnChangeHeightEdit() if (1==sscanf(buffer, "%d", &height)) { m_currentHeight = height; BrushTool::setHeight(m_currentHeight); - sprintf(buffer, "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp index fe25fa7eee..a7ecc56e9f 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp @@ -472,9 +472,9 @@ void MapObjectProps::_ScaleToDict(void) void MapObjectProps::ShowZOffset(MapObject *pMapObj) { const Coord3D *loc = pMapObj->getLocation(); - static char buff[12]; + static char buff[64]; m_height = loc->z; - sprintf(buff, "%0.2f", loc->z); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", loc->z); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); } @@ -504,8 +504,8 @@ void MapObjectProps::SetZOffset(void) void MapObjectProps::ShowAngle(MapObject *pMapObj) { m_angle = pMapObj->getAngle() * 180 / PI; - static char buff[12]; - sprintf(buff, "%0.2f", m_angle); + static char buff[64]; + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); m_angle = atof(buff); @@ -515,8 +515,8 @@ void MapObjectProps::ShowAngle(MapObject *pMapObj) void MapObjectProps::ShowPosition(MapObject *pMapObj) { m_position = *pMapObj->getLocation(); - static char buff[12]; - sprintf(buff, "%0.2f, %0.2f", m_position.x, m_position.y); + static char buff[128]; + snprintf(buff, ARRAY_SIZE(buff), "%0.2f, %0.2f", m_position.x, m_position.y); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_XYPosition); edit->SetWindowText(buff); sscanf(buff, "%f,%f", &m_position.x, &m_position.y); @@ -617,7 +617,7 @@ void MapObjectProps::PopSliderChanged(const long sliderID, long theVal) return; CWnd* edit; - static char buff[36]; + static char buff[64]; switch (sliderID) { case IDC_HEIGHT_POPUP: if (!m_posUndoable) { @@ -626,7 +626,7 @@ void MapObjectProps::PopSliderChanged(const long sliderID, long theVal) } m_posUndoable->SetZOffset(theVal); m_height = theVal; - sprintf(buff, "%0.2f", m_height); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height); edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); break; @@ -638,14 +638,14 @@ void MapObjectProps::PopSliderChanged(const long sliderID, long theVal) } m_posUndoable->RotateTo(theVal * PI/180); m_angle = theVal; - sprintf(buff, "%0.2f", m_angle); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); break; case IDC_SCALE_POPUP: m_scale = theVal/100.0f; - sprintf(buff, "%0.2f", m_scale); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_scale); edit = GetDlgItem(IDC_MAPOBJECT_Scale); edit->SetWindowText(buff); break; @@ -885,7 +885,7 @@ void MapObjectProps::_DictToHealth(void) } else { pItem->SelectString(-1, "Other"); static char buff[12]; - sprintf(buff, "%d", value); + snprintf(buff, ARRAY_SIZE(buff), "%d", value); pItem2->SetWindowText(buff); pItem2->EnableWindow(TRUE); } @@ -1035,7 +1035,7 @@ void MapObjectProps::_DictToVisibilityRange(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_VisionDistance); if (pItem) { static char buff[12]; - sprintf(buff, "%d", distance); + snprintf(buff, ARRAY_SIZE(buff), "%d", distance); if (distance == 0) { pItem->SetWindowText(""); } else { @@ -1071,7 +1071,7 @@ void MapObjectProps::_DictToShroudClearingDistance(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_ShroudClearingDistance); if (pItem) { static char buff[12]; - sprintf(buff, "%d", distance); + snprintf(buff, ARRAY_SIZE(buff), "%d", distance); if (distance == 0) { pItem->SetWindowText(""); } else { @@ -1124,8 +1124,8 @@ void MapObjectProps::_DictToStoppingDistance(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_StoppingDistance); if (pItem) { - static char buff[12]; - sprintf(buff, "%g", stoppingDistance); + static char buff[64]; + snprintf(buff, ARRAY_SIZE(buff), "%g", stoppingDistance); pItem->SetWindowText(buff); } } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp index fd24788427..1c8d56fdf5 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp @@ -568,11 +568,11 @@ void PlayerListDlg::updateTheUI(void) pname = playerNameForUI(m_sides, i); rstr = calcRelationStr(m_sides, m_curPlayerIdx, i); - sprintf(buffer, "%s: %s",pname.str(),rstr); + snprintf(buffer, ARRAY_SIZE(buffer), "%s: %s",pname.str(),rstr); regardOthers->AddString(buffer); rstr = calcRelationStr(m_sides, i, m_curPlayerIdx); - sprintf(buffer, "%s: %s",pname.str(),rstr); + snprintf(buffer, ARRAY_SIZE(buffer), "%s: %s",pname.str(),rstr); regardMe->AddString(buffer); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp index 751e1d830d..9a4941f669 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp @@ -2579,7 +2579,7 @@ void WbView3d::drawLabels(HDC hdc) if (m_lightFeedbackMesh[lIndex] == NULL) { char nameBuf[64]; - sprintf(nameBuf,"WB_LIGHT%d",lIndex+1); + snprintf(nameBuf,ARRAY_SIZE(nameBuf),"WB_LIGHT%d",lIndex+1); m_lightFeedbackMesh[lIndex]=WW3DAssetManager::Get_Instance()->Create_Render_Obj(nameBuf); } if (m_lightFeedbackMesh[lIndex]==NULL) { From 6d386869d3f71c4abd668be39c8f8648eef5f98e Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Wed, 22 Oct 2025 18:41:17 +0200 Subject: [PATCH 2/4] Decrease float string buffer sizes from 64 to 32 --- GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp | 4 ++-- .../Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp | 2 +- .../Code/Tools/WorldBuilder/src/mapobjectprops.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp index 773687461d..0fdd34cb72 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -449,7 +449,7 @@ void BuildList::OnSelchangeBuildList() PointerTool::clearSelection(); // unselect other stuff. if (pBuildInfo) { CWnd *edit; - static char buff[64]; + static char buff[32]; pBuildInfo->setSelected(true); m_angle = pBuildInfo->getAngle() * 180/PI; @@ -638,7 +638,7 @@ void BuildList::PopSliderChanged(const long sliderID, long theVal) { // CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); CWnd* edit; - static char buff[64]; + static char buff[32]; switch (sliderID) { case IDC_HEIGHT_POPUP: m_height = theVal; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp index a742e5841c..6e1e94fb7e 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp @@ -148,7 +148,7 @@ BOOL MeshMoldOptions::OnInitDialog() void MeshMoldOptions::setHeight(Real height) { - char buffer[64]; + char buffer[32]; snprintf(buffer, ARRAY_SIZE(buffer), "%.2f", height); m_currentHeight = height; if (m_staticThis && !m_staticThis->m_updating) { diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp index a7ecc56e9f..b47b83f46f 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp @@ -472,7 +472,7 @@ void MapObjectProps::_ScaleToDict(void) void MapObjectProps::ShowZOffset(MapObject *pMapObj) { const Coord3D *loc = pMapObj->getLocation(); - static char buff[64]; + static char buff[32]; m_height = loc->z; snprintf(buff, ARRAY_SIZE(buff), "%0.2f", loc->z); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); @@ -504,7 +504,7 @@ void MapObjectProps::SetZOffset(void) void MapObjectProps::ShowAngle(MapObject *pMapObj) { m_angle = pMapObj->getAngle() * 180 / PI; - static char buff[64]; + static char buff[32]; snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); @@ -515,7 +515,7 @@ void MapObjectProps::ShowAngle(MapObject *pMapObj) void MapObjectProps::ShowPosition(MapObject *pMapObj) { m_position = *pMapObj->getLocation(); - static char buff[128]; + static char buff[64]; snprintf(buff, ARRAY_SIZE(buff), "%0.2f, %0.2f", m_position.x, m_position.y); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_XYPosition); edit->SetWindowText(buff); @@ -617,7 +617,7 @@ void MapObjectProps::PopSliderChanged(const long sliderID, long theVal) return; CWnd* edit; - static char buff[64]; + static char buff[32]; switch (sliderID) { case IDC_HEIGHT_POPUP: if (!m_posUndoable) { @@ -1124,7 +1124,7 @@ void MapObjectProps::_DictToStoppingDistance(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_StoppingDistance); if (pItem) { - static char buff[64]; + static char buff[32]; snprintf(buff, ARRAY_SIZE(buff), "%g", stoppingDistance); pItem->SetWindowText(buff); } From 773fd71294846f968176d9e79835225eecb7ab65 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Wed, 22 Oct 2025 18:42:38 +0200 Subject: [PATCH 3/4] Fix format --- GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp index 9a4941f669..2cfa7e5fcd 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp @@ -2579,7 +2579,7 @@ void WbView3d::drawLabels(HDC hdc) if (m_lightFeedbackMesh[lIndex] == NULL) { char nameBuf[64]; - snprintf(nameBuf,ARRAY_SIZE(nameBuf),"WB_LIGHT%d",lIndex+1); + snprintf(nameBuf, ARRAY_SIZE(nameBuf), "WB_LIGHT%d", lIndex+1); m_lightFeedbackMesh[lIndex]=WW3DAssetManager::Get_Instance()->Create_Render_Obj(nameBuf); } if (m_lightFeedbackMesh[lIndex]==NULL) { From 284142e9d322240ae243ac1e4ad70db5a91fd492 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Wed, 22 Oct 2025 19:44:45 +0200 Subject: [PATCH 4/4] Replicate in Generals --- .../Code/Tools/WorldBuilder/include/StdAfx.h | 2 +- .../Tools/WorldBuilder/src/BaseBuildProps.cpp | 2 +- .../Tools/WorldBuilder/src/BlendMaterial.cpp | 2 +- .../Code/Tools/WorldBuilder/src/BuildList.cpp | 12 +++++----- .../Tools/WorldBuilder/src/EditParameter.cpp | 2 +- .../Tools/WorldBuilder/src/FeatherOptions.cpp | 2 +- .../Tools/WorldBuilder/src/GroveOptions.cpp | 14 +++++------ .../Tools/WorldBuilder/src/LayersList.cpp | 2 +- .../WorldBuilder/src/MeshMoldOptions.cpp | 12 +++++----- .../Tools/WorldBuilder/src/MoundOptions.cpp | 10 ++++---- .../Code/Tools/WorldBuilder/src/SaveMap.cpp | 2 +- .../WorldBuilder/src/TerrainMaterial.cpp | 4 ++-- .../Tools/WorldBuilder/src/WHeightMapEdit.cpp | 2 +- .../Tools/WorldBuilder/src/WaterOptions.cpp | 12 +++++----- .../Tools/WorldBuilder/src/WorldBuilder.cpp | 2 +- .../Tools/WorldBuilder/src/brushoptions.cpp | 10 ++++---- .../Tools/WorldBuilder/src/mapobjectprops.cpp | 24 +++++++++---------- .../Tools/WorldBuilder/src/playerlistdlg.cpp | 4 ++-- .../Code/Tools/WorldBuilder/src/wbview3d.cpp | 2 +- 19 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Generals/Code/Tools/WorldBuilder/include/StdAfx.h b/Generals/Code/Tools/WorldBuilder/include/StdAfx.h index d0736dfc88..6ae112a262 100644 --- a/Generals/Code/Tools/WorldBuilder/include/StdAfx.h +++ b/Generals/Code/Tools/WorldBuilder/include/StdAfx.h @@ -42,7 +42,7 @@ #include // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT - +#include //{{AFX_INSERT_LOCATION}} diff --git a/Generals/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp b/Generals/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp index 6a0b35566d..cd7adaf8f3 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BaseBuildProps.cpp @@ -66,7 +66,7 @@ BOOL BaseBuildProps::OnInitDialog() // add health CWnd* pHealth = GetDlgItem(IDC_MAPOBJECT_StartingHealthEdit); static char buff[12]; - sprintf(buff, "%d", m_health); + snprintf(buff, ARRAY_SIZE(buff), "%d", m_health); pHealth->SetWindowText(buff); CButton* pItem; diff --git a/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp b/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp index ed49810783..dd62d120a9 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp @@ -208,7 +208,7 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare // Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles; char label[_MAX_PATH]; - sprintf(label, "%s", buffer); + snprintf(label, ARRAY_SIZE(label), "%s", buffer); if( doAdd ) diff --git a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp index 831ad919f4..a1dcb05cc1 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -449,16 +449,16 @@ void BuildList::OnSelchangeBuildList() PointerTool::clearSelection(); // unselect other stuff. if (pBuildInfo) { CWnd *edit; - static char buff[12]; + static char buff[32]; pBuildInfo->setSelected(true); m_angle = pBuildInfo->getAngle() * 180/PI; - sprintf(buff, "%0.2f", m_angle); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); m_height = pBuildInfo->getLocation()->z; - sprintf(buff, "%0.2f", m_height); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height); edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); @@ -638,11 +638,11 @@ void BuildList::PopSliderChanged(const long sliderID, long theVal) { // CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); CWnd* edit; - static char buff[12]; + static char buff[32]; switch (sliderID) { case IDC_HEIGHT_POPUP: m_height = theVal; - sprintf(buff, "%0.2f", m_height); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height); edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); OnChangeZOffset(); @@ -650,7 +650,7 @@ void BuildList::PopSliderChanged(const long sliderID, long theVal) case IDC_ANGLE_POPUP: m_angle = theVal; - sprintf(buff, "%0.2f", m_angle); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); break; diff --git a/Generals/Code/Tools/WorldBuilder/src/EditParameter.cpp b/Generals/Code/Tools/WorldBuilder/src/EditParameter.cpp index fc43e739ad..3f8321d85c 100644 --- a/Generals/Code/Tools/WorldBuilder/src/EditParameter.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/EditParameter.cpp @@ -1332,7 +1332,7 @@ void EditParameter::readFontFile( const char *filename ) { char buffer[ 1024 ]; - sprintf( buffer, "Warning: The font '%s' Size: '%d' Bold: '%d', specified in the config file could not be loaded. Does that font exist?", + snprintf( buffer, ARRAY_SIZE(buffer), "Warning: The font '%s' Size: '%d' Bold: '%d', specified in the config file could not be loaded. Does that font exist?", fontBuffer, size, bold ); //MessageBox( m_appHWnd, buffer, "Cannot Load Font", MB_OK ); diff --git a/Generals/Code/Tools/WorldBuilder/src/FeatherOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/FeatherOptions.cpp index fb4bbfd37d..e836537407 100644 --- a/Generals/Code/Tools/WorldBuilder/src/FeatherOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/FeatherOptions.cpp @@ -134,7 +134,7 @@ void FeatherOptions::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentFeather = width; FeatherTool::setFeather(m_currentFeather); - sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/Generals/Code/Tools/WorldBuilder/src/GroveOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/GroveOptions.cpp index 15a304f1fc..b0cb541a0f 100644 --- a/Generals/Code/Tools/WorldBuilder/src/GroveOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/GroveOptions.cpp @@ -266,35 +266,35 @@ void GroveOptions::_setDefaultRatios(void) CWnd* pWnd = GetDlgItem(IDC_Grove_Per1); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio1", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per2); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio2", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per3); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio3", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per4); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio4", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } pWnd = GetDlgItem(IDC_Grove_Per5); if (pWnd) { defaultRatio = AfxGetApp()->GetProfileInt("GroveOptions", "DefaultRatio5", 0); - sprintf(buff, "%d", defaultRatio); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultRatio); pWnd->SetWindowText(buff); } } @@ -308,7 +308,7 @@ void GroveOptions::_setDefaultNumTrees(void) int defaultNumTrees = AfxGetApp()->GetProfileInt("GroveOptions", "NumberofTrees", 10); static char buff[ARBITRARY_BUFF_SIZE]; - sprintf(buff, "%d", defaultNumTrees); + snprintf(buff, ARRAY_SIZE(buff), "%d", defaultNumTrees); pWnd->SetWindowText(buff); } @@ -379,7 +379,7 @@ void GroveOptions::_updateTreeWeights(void) pWnd = GetDlgItem(IDC_Grove_PerTotal); if (pWnd) { - sprintf(buff, "%d", val); + snprintf(buff, ARRAY_SIZE(buff), "%d", val); pWnd->SetWindowText(buff); } } diff --git a/Generals/Code/Tools/WorldBuilder/src/LayersList.cpp b/Generals/Code/Tools/WorldBuilder/src/LayersList.cpp index d89ac36b7f..a055af1b36 100644 --- a/Generals/Code/Tools/WorldBuilder/src/LayersList.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/LayersList.cpp @@ -588,7 +588,7 @@ void LayersList::OnNewLayer() } static char buffer[1024]; - sprintf(buffer, "%s %d", TheDefaultNewLayerName.c_str(), newLayerNum); + snprintf(buffer, ARRAY_SIZE(buffer), "%s %d", TheDefaultNewLayerName.c_str(), newLayerNum); addLayerNamed(buffer); HTREEITEM newItem = pTree->InsertItem(buffer, 0, 0); diff --git a/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp index b8311dc864..86da580532 100644 --- a/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp @@ -142,8 +142,8 @@ BOOL MeshMoldOptions::OnInitDialog() void MeshMoldOptions::setHeight(Real height) { - char buffer[50]; - sprintf(buffer, "%.2f", height); + char buffer[32]; + snprintf(buffer, ARRAY_SIZE(buffer), "%.2f", height); m_currentHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -154,8 +154,8 @@ void MeshMoldOptions::setHeight(Real height) void MeshMoldOptions::setScale(Real scale) { - char buffer[50]; - sprintf(buffer, "%d", (int)floor(scale*100)); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", (int)floor(scale*100)); m_currentScale = scale; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_SCALE_EDIT); @@ -166,8 +166,8 @@ void MeshMoldOptions::setScale(Real scale) void MeshMoldOptions::setAngle(Int angle) { - char buffer[50]; - sprintf(buffer, "%d", angle); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", angle); m_currentAngle = angle; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_ANGLE_EDIT); diff --git a/Generals/Code/Tools/WorldBuilder/src/MoundOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/MoundOptions.cpp index c40a69587d..8bdc6b806d 100644 --- a/Generals/Code/Tools/WorldBuilder/src/MoundOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/MoundOptions.cpp @@ -78,8 +78,8 @@ void MoundOptions::setWidth(Int width) void MoundOptions::setHeight(Int height) { - char buffer[50]; - sprintf(buffer, "%d", height); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", height); m_currentHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -129,7 +129,7 @@ void MoundOptions::OnChangeFeatherEdit() if (1==sscanf(buffer, "%d", &feather)) { m_currentFeather = feather; MoundTool::setFeather(m_currentFeather); - sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -152,7 +152,7 @@ void MoundOptions::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentWidth = width; MoundTool::setWidth(m_currentWidth); - sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -175,7 +175,7 @@ void MoundOptions::OnChangeHeightEdit() if (1==sscanf(buffer, "%d", &height)) { m_currentHeight = height; MoundTool::setMoundHeight(m_currentHeight); - sprintf(buffer, "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp b/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp index cb70c42ccb..cc7b029e45 100644 --- a/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp @@ -128,7 +128,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) if (systemMaps) strcpy(dirBuf, ".\\Maps\\"); else - sprintf(dirBuf, "%sMaps\\", TheGlobalData->getPath_UserData().str()); + snprintf(dirBuf, ARRAY_SIZE(dirBuf), "%sMaps\\", TheGlobalData->getPath_UserData().str()); int len = strlen(dirBuf); if (len > 0 && dirBuf[len - 1] != '\\') { diff --git a/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp b/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp index 679f261a0a..d8b75321a7 100644 --- a/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp @@ -336,7 +336,7 @@ void TerrainMaterial::addTerrain(char *pPath, Int terrainNdx, HTREEITEM parent) Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles; char label[_MAX_PATH]; - sprintf(label, "%d%% %s", percent, buffer); + snprintf(label, ARRAY_SIZE(label), "%d%% %s", percent, buffer); if( doAdd ) @@ -405,7 +405,7 @@ void TerrainMaterial::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentWidth = width; BigTileTool::setWidth(m_currentWidth); - sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 5c87b65e96..2bd85b9c81 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -457,7 +457,7 @@ void WorldHeightMapEdit::loadImagesFromTerrainType( TerrainType *terrain ) char buffer[ _MAX_PATH ]; // build path to texture file - sprintf( buffer, "%s%s", TERRAIN_TGA_DIR_PATH, terrain->getTexture().str() ); + snprintf( buffer, ARRAY_SIZE(buffer), "%s%s", TERRAIN_TGA_DIR_PATH, terrain->getTexture().str() ); // create ascii string for texture path AsciiString texturePath( buffer ); diff --git a/Generals/Code/Tools/WorldBuilder/src/WaterOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/WaterOptions.cpp index 5493b5789f..e716b431b4 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WaterOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WaterOptions.cpp @@ -61,8 +61,8 @@ void WaterOptions::DoDataExchange(CDataExchange* pDX) void WaterOptions::setHeight(Int height) { - char buffer[50]; - sprintf(buffer, "%d", height); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", height); m_waterHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -91,9 +91,9 @@ void WaterOptions::updateTheUI(void) pButton->EnableWindow(theTrigger!=NULL); pWnd = m_staticThis->GetDlgItem(IDC_SPACING); - char buffer[_MAX_PATH]; + char buffer[12]; if (pWnd) { - sprintf(buffer, "%d", m_waterPointSpacing); + snprintf(buffer, ARRAY_SIZE(buffer), "%d", m_waterPointSpacing); pWnd->SetWindowText(buffer); } } @@ -492,7 +492,7 @@ void WaterOptions::OnChangeSpacingEdit() { if (m_updating) return; CWnd *pEdit = m_staticThis->GetDlgItem(IDC_SPACING); - char buffer[_MAX_PATH]; + char buffer[12]; if (pEdit) { pEdit->GetWindowText(buffer, sizeof(buffer)); Int height; @@ -500,7 +500,7 @@ void WaterOptions::OnChangeSpacingEdit() if (1==sscanf(buffer, "%d", &height)) { m_waterPointSpacing = height; } else { - sprintf(buffer, "%d", m_waterPointSpacing); + snprintf(buffer, ARRAY_SIZE(buffer), "%d", m_waterPointSpacing); pEdit->SetWindowText(buffer); } m_updating = false; diff --git a/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp b/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp index fb897701ec..10a160c18a 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp @@ -363,7 +363,7 @@ BOOL CWorldBuilderApp::InitInstance() strcpy((char*)m_pszProfileName, buf); // ensure the user maps dir exists - sprintf(buf, "%sMaps\\", TheGlobalData->getPath_UserData().str()); + snprintf(buf, ARRAY_SIZE(buf), "%sMaps\\", TheGlobalData->getPath_UserData().str()); CreateDirectory(buf, NULL); // read the water settings from INI (must do prior to initing GameClient, apparently) diff --git a/Generals/Code/Tools/WorldBuilder/src/brushoptions.cpp b/Generals/Code/Tools/WorldBuilder/src/brushoptions.cpp index 022377789b..030a00630b 100644 --- a/Generals/Code/Tools/WorldBuilder/src/brushoptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/brushoptions.cpp @@ -78,8 +78,8 @@ void BrushOptions::setWidth(Int width) void BrushOptions::setHeight(Int height) { - char buffer[50]; - sprintf(buffer, "%d", height); + char buffer[12]; + snprintf(buffer, ARRAY_SIZE(buffer), "%d", height); m_currentHeight = height; if (m_staticThis && !m_staticThis->m_updating) { CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT); @@ -129,7 +129,7 @@ void BrushOptions::OnChangeFeatherEdit() if (1==sscanf(buffer, "%d", &feather)) { m_currentFeather = feather; BrushTool::setFeather(m_currentFeather); - sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -152,7 +152,7 @@ void BrushOptions::OnChangeSizeEdit() if (1==sscanf(buffer, "%d", &width)) { m_currentWidth = width; BrushTool::setWidth(m_currentWidth); - sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR); pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } @@ -175,7 +175,7 @@ void BrushOptions::OnChangeHeightEdit() if (1==sscanf(buffer, "%d", &height)) { m_currentHeight = height; BrushTool::setHeight(m_currentHeight); - sprintf(buffer, "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); + snprintf(buffer, ARRAY_SIZE(buffer), "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE); pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_LABEL); if (pEdit) pEdit->SetWindowText(buffer); } diff --git a/Generals/Code/Tools/WorldBuilder/src/mapobjectprops.cpp b/Generals/Code/Tools/WorldBuilder/src/mapobjectprops.cpp index eaee6f6f14..cad7018834 100644 --- a/Generals/Code/Tools/WorldBuilder/src/mapobjectprops.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/mapobjectprops.cpp @@ -422,7 +422,7 @@ void MapObjectProps::_DictToHealth(void) } else { pItem->SelectString(-1, "Other"); static char buff[12]; - sprintf(buff, "%d", value); + snprintf(buff, ARRAY_SIZE(buff), "%d", value); pItem2->SetWindowText(buff); pItem2->EnableWindow(TRUE); } @@ -582,7 +582,7 @@ void MapObjectProps::_DictToVisibilityRange(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_VisionDistance); if (pItem) { static char buff[12]; - sprintf(buff, "%d", distance); + snprintf(buff, ARRAY_SIZE(buff), "%d", distance); if (distance == 0) { pItem->SetWindowText(""); } else { @@ -644,7 +644,7 @@ void MapObjectProps::_DictToShroudClearingDistance(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_ShroudClearingDistance); if (pItem) { static char buff[12]; - sprintf(buff, "%d", distance); + snprintf(buff, ARRAY_SIZE(buff), "%d", distance); if (distance == 0) { pItem->SetWindowText(""); } else { @@ -691,8 +691,8 @@ void MapObjectProps::_DictToStoppingDistance(void) CWnd* pItem = GetDlgItem(IDC_MAPOBJECT_StoppingDistance); if (pItem) { - static char buff[12]; - sprintf(buff, "%g", stoppingDistance); + static char buff[32]; + snprintf(buff, ARRAY_SIZE(buff), "%g", stoppingDistance); pItem->SetWindowText(buff); } } @@ -1262,9 +1262,9 @@ void MapObjectProps::OnCancel() void MapObjectProps::ShowZOffset(MapObject *pMapObj) { const Coord3D *loc = pMapObj->getLocation(); - static char buff[12]; + static char buff[32]; m_height = loc->z; - sprintf(buff, "%0.2f", loc->z); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", loc->z); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); } @@ -1289,8 +1289,8 @@ void MapObjectProps::SetZOffset(void) void MapObjectProps::ShowAngle(MapObject *pMapObj) { m_angle = pMapObj->getAngle() * 180 / PI; - static char buff[12]; - sprintf(buff, "%0.2f", m_angle); + static char buff[32]; + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); CWnd* edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); @@ -1380,7 +1380,7 @@ void MapObjectProps::PopSliderChanged(const long sliderID, long theVal) { CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); CWnd* edit; - static char buff[12]; + static char buff[32]; switch (sliderID) { case IDC_HEIGHT_POPUP: if (!m_posUndoable) { @@ -1389,7 +1389,7 @@ void MapObjectProps::PopSliderChanged(const long sliderID, long theVal) } m_posUndoable->SetZOffset(theVal); m_height = theVal; - sprintf(buff, "%0.2f", m_height); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_height); edit = GetDlgItem(IDC_MAPOBJECT_ZOffset); edit->SetWindowText(buff); break; @@ -1401,7 +1401,7 @@ void MapObjectProps::PopSliderChanged(const long sliderID, long theVal) } m_posUndoable->RotateTo(theVal * PI/180); m_angle = theVal; - sprintf(buff, "%0.2f", m_angle); + snprintf(buff, ARRAY_SIZE(buff), "%0.2f", m_angle); edit = GetDlgItem(IDC_MAPOBJECT_Angle); edit->SetWindowText(buff); break; diff --git a/Generals/Code/Tools/WorldBuilder/src/playerlistdlg.cpp b/Generals/Code/Tools/WorldBuilder/src/playerlistdlg.cpp index 3134f1e228..e66da5dde4 100644 --- a/Generals/Code/Tools/WorldBuilder/src/playerlistdlg.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/playerlistdlg.cpp @@ -567,11 +567,11 @@ void PlayerListDlg::updateTheUI(void) pname = playerNameForUI(m_sides, i); rstr = calcRelationStr(m_sides, m_curPlayerIdx, i); - sprintf(buffer, "%s: %s",pname.str(),rstr); + snprintf(buffer, ARRAY_SIZE(buffer), "%s: %s",pname.str(),rstr); regardOthers->AddString(buffer); rstr = calcRelationStr(m_sides, i, m_curPlayerIdx); - sprintf(buffer, "%s: %s",pname.str(),rstr); + snprintf(buffer, ARRAY_SIZE(buffer), "%s: %s",pname.str(),rstr); regardMe->AddString(buffer); } diff --git a/Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp b/Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp index 1bb3ce444e..b867dd42fa 100644 --- a/Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp @@ -2433,7 +2433,7 @@ void WbView3d::drawLabels(HDC hdc) if (m_lightFeedbackMesh[lIndex] == NULL) { char nameBuf[64]; - sprintf(nameBuf,"WB_LIGHT%d",lIndex+1); + snprintf(nameBuf, ARRAY_SIZE(nameBuf), "WB_LIGHT%d", lIndex+1); m_lightFeedbackMesh[lIndex]=WW3DAssetManager::Get_Instance()->Create_Render_Obj(nameBuf); } if (m_lightFeedbackMesh[lIndex]==NULL) {