diff --git a/Generals/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/Generals/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp index 3c5d84a01e..ee1d58a385 100644 --- a/Generals/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp @@ -847,14 +847,13 @@ static AsciiString getMapLeafAndDirName(const AsciiString& in) // ------------------------------------------------------------------------------------------------ static AsciiString removeExtension(const AsciiString& in) { - char buf[1024]; - strcpy(buf, in.str()); - char* p = strrchr(buf, '.'); - if (p) + if (const char* end = in.reverseFind('.')) { - *p = 0; + const char* begin = in.str(); + return AsciiString(begin, end - begin); } - return AsciiString(buf); + + return in; } // ------------------------------------------------------------------------------------------------ @@ -1619,22 +1618,16 @@ void GameState::xfer( Xfer *xfer ) saveGameInfo->mapLabel = dict->getAsciiString( TheKey_mapName, &exists ); // if no label was found, we'll use the map name (just filename, no directory info) - if( exists == FALSE || saveGameInfo->mapLabel == AsciiString::TheEmptyString ) + if (exists == FALSE || saveGameInfo->mapLabel == AsciiString::TheEmptyString) { - char string[ _MAX_PATH ]; - - strcpy( string, TheGlobalData->m_mapName.str() ); - char *p = strrchr( string, '\\' ); - if( p == NULL ) + const char* p = TheGlobalData->m_mapName.reverseFind('\\'); + if (p == NULL) saveGameInfo->mapLabel = TheGlobalData->m_mapName; else { - p++; // skip the '\' we're on - saveGameInfo->mapLabel.set( p ); - + saveGameInfo->mapLabel.set(p); } - } // xfer map label diff --git a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp index 8ec0428b67..33ef3062da 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp @@ -219,11 +219,9 @@ void JoinDirectConnectGame() AsciiString ipstring; asciientry.nextToken(&ipstring, "("); - char ipstr[16]; - strcpy(ipstr, ipstring.str()); - Int ip1, ip2, ip3, ip4; - sscanf(ipstr, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4); + Int numFields = sscanf(ipstring.str(), "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4); + (void)numFields; DEBUG_ASSERTCRASH(numFields == 4, ("JoinDirectConnectGame - invalid IP address format: %s", ipstring.str())); DEBUG_LOG(("JoinDirectConnectGame - joining at %d.%d.%d.%d", ip1, ip2, ip3, ip4)); diff --git a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp index 18983286d4..441dbcb3fc 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp @@ -2550,11 +2550,10 @@ void ScriptActions::doDisplayCinematicText(const AsciiString& displayText, const // get the font name AsciiString fontName = AsciiString::TheEmptyString; - char buf[256]; - char *c; - strcpy(buf, fontType.str()); + // TheSuperHackers @fix xezon 22/03/2025 Fixes potential buffer overrun via prior c!='\0' test. - for( c = buf; *c != '\0'; c++ ) + const char* c = fontType.str(); + for (; *c != '\0'; c++) { if( *c != ' ' && *c++ != '-' ) fontName.concat(c); diff --git a/Generals/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp b/Generals/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp index db8f89194b..fd373a8419 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp @@ -679,9 +679,7 @@ Bool FirewallHelperClass::detectionBeginUpdate() { /* ** Do the lookup. */ - char temp_name[256]; - strcpy(temp_name, mangler_name_ptr); - struct hostent *host_info = gethostbyname(temp_name); + struct hostent *host_info = gethostbyname(mangler_name_ptr); if (!host_info) { DEBUG_LOG(("gethostbyname failed! Error code %d", WSAGetLastError())); diff --git a/Generals/Code/GameEngine/Source/GameNetwork/udp.cpp b/Generals/Code/GameEngine/Source/GameNetwork/udp.cpp index bcbc61b5f8..9e9dbd7449 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/udp.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/udp.cpp @@ -127,15 +127,12 @@ UDP::~UDP() Int UDP::Bind(const char *Host,UnsignedShort port) { - char hostName[100]; struct hostent *hostStruct; struct in_addr *hostNode; if (isdigit(Host[0])) return ( Bind( ntohl(inet_addr(Host)), port) ); - strcpy(hostName, Host); - hostStruct = gethostbyname(Host); if (hostStruct == NULL) return (0); diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp index 1870b062d9..2ae50e8ebf 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp @@ -232,14 +232,12 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_W3D ) { sprintf(m_filePath,USER_W3D_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_W3D_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } else if( isImageFileType(fileType) ) { sprintf(m_filePath,USER_TGA_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_TGA_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } @@ -256,7 +254,6 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_TGA ) // just TGA, since we don't do dds previews { sprintf(m_filePath,MAP_PREVIEW_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_TGA_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp index 0c34f99695..cb4ed6f216 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp @@ -117,22 +117,6 @@ Bool W3DTerrainLogic::loadMap( AsciiString filename , Bool query ) WorldHeightMap *terrainHeightMap; ///< holds raw heightmap data samples - char tempBuf[_MAX_PATH]; - char filenameBuf[_MAX_PATH]; - int length = 0; - - strcpy(tempBuf, filename.str()); - - length = strlen( tempBuf ); - if( length >= 4 ) - { - strlcpy( filenameBuf, tempBuf, length - 4 + 1); - } - -// const char *fname = filename.reverseFind('\\'); -// if (fname) -// filename = fname+1; - CachedFileInputStream fileStrm; if ( !fileStrm.open(filename) ) { diff --git a/Generals/Code/Tools/GUIEdit/Source/GUIEdit.cpp b/Generals/Code/Tools/GUIEdit/Source/GUIEdit.cpp index 5227b26e3e..4c38d26286 100644 --- a/Generals/Code/Tools/GUIEdit/Source/GUIEdit.cpp +++ b/Generals/Code/Tools/GUIEdit/Source/GUIEdit.cpp @@ -3539,7 +3539,6 @@ void GUIEdit::stripNameDecorations( GameWindow *root ) if( !instData->m_decoratedNameString.isEmpty() ) { - char nameOnly[ MAX_WINDOW_NAME_LEN ]; const char *c; // skip past the "filename.wnd:" to the name only @@ -3550,11 +3549,8 @@ void GUIEdit::stripNameDecorations( GameWindow *root ) // skip beyong the scope resolution colon c++; - // copy the name - strcpy( nameOnly, c ); - // put the name only in the decoration field - instData->m_decoratedNameString = nameOnly; + instData->m_decoratedNameString = c; } diff --git a/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp b/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp index dd62d120a9..3eaa72618e 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp @@ -207,10 +207,6 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare // Int availableTiles = 4 * tilesPerRow * tilesPerRow; // Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles; - char label[_MAX_PATH]; - snprintf(label, ARRAY_SIZE(label), "%s", buffer); - - if( doAdd ) { TVINSERTSTRUCT ins; @@ -220,8 +216,8 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare ins.hInsertAfter = TVI_LAST; ins.item.mask = TVIF_PARAM|TVIF_TEXT; ins.item.lParam = terrainNdx; - ins.item.pszText = label; - ins.item.cchTextMax = strlen(label)+2; + ins.item.pszText = buffer; + ins.item.cchTextMax = strlen(buffer)+2; m_terrainTreeView.InsertItem(&ins); } diff --git a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp index 60b8428399..3b677d78e5 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -737,24 +737,20 @@ void BuildList::OnExport() static FILE *theLogFile = NULL; Bool open = false; try { - char dirbuf[ _MAX_PATH ]; - ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - if (char *pEnd = strrchr(dirbuf, '\\')) + char buffer[ _MAX_PATH ]; + ::GetModuleFileName( NULL, buffer, sizeof( buffer ) ); + if (char *pEnd = strrchr(buffer, '\\')) { *(pEnd + 1) = 0; } - char curbuf[ _MAX_PATH ]; - - strcpy(curbuf, dirbuf); SidesInfo *pSide = TheSidesList->getSideInfo(m_curSide); Dict *d = TheSidesList->getSideInfo(m_curSide)->getDict(); AsciiString name = d->getAsciiString(TheKey_playerName); - strlcat(curbuf, name.str(), ARRAY_SIZE(curbuf)); - strlcat(curbuf, "_BuildList", ARRAY_SIZE(curbuf)); - strlcat(curbuf, ".ini", ARRAY_SIZE(curbuf)); + strlcat(buffer, name.str(), ARRAY_SIZE(buffer)); + strlcat(buffer, "_BuildList.ini", ARRAY_SIZE(buffer)); - theLogFile = fopen(curbuf, "w"); + theLogFile = fopen(buffer, "w"); if (theLogFile == NULL) throw; diff --git a/Generals/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp b/Generals/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp index fe38881e93..72fa568592 100644 --- a/Generals/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp @@ -100,7 +100,6 @@ BOOL EditObjectParameter::OnInitDialog() //------------------------------------------------------------------------------------------------- void EditObjectParameter::addObject( const ThingTemplate *thingTemplate ) { - char buffer[ _MAX_PATH ]; HTREEITEM parent = TVI_ROOT; const char *leafName; // @@ -121,8 +120,7 @@ void EditObjectParameter::addObject( const ThingTemplate *thingTemplate ) // first sort by Side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH(!side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/Generals/Code/Tools/WorldBuilder/src/FenceOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/FenceOptions.cpp index 6c42f202c4..0b4885ad5c 100644 --- a/Generals/Code/Tools/WorldBuilder/src/FenceOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/FenceOptions.cpp @@ -236,7 +236,6 @@ HTREEITEM FenceOptions::findOrAdd(HTREEITEM parent, const char *pLabel) void FenceOptions::addObject( MapObject *mapObject, const char *pPath, const char *name, Int terrainNdx, HTREEITEM parent ) { - char buffer[ _MAX_PATH ]; const char *leafName = NULL; // sanity @@ -262,8 +261,7 @@ void FenceOptions::addObject( MapObject *mapObject, const char *pPath, const cha // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp index 86da580532..46931a87a9 100644 --- a/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp @@ -80,23 +80,11 @@ BOOL MeshMoldOptions::OnInitDialog() m_moldTreeView.ShowWindow(SW_SHOW); { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; Int i; - strcpy(dirBuf, ".\\data\\Editor\\Molds"); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.w3d", ARRAY_SIZE(findBuf)); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.w3d"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory(".\\data\\Editor\\Molds\\", "*.w3d", filenameList, FALSE); if (filenameList.size() > 0) { HTREEITEM child = NULL; @@ -104,7 +92,7 @@ BOOL MeshMoldOptions::OnInitDialog() do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; strcpy(fileBuf, filename.str()); for (i=strlen(fileBuf)-1; i>0; i--) { diff --git a/Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp index d60794cc75..4490424518 100644 --- a/Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp @@ -277,29 +277,17 @@ BOOL ObjectOptions::OnInitDialog() #endif #ifdef LOAD_TEST_ASSETS { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; Int i; - strcpy(dirBuf, TEST_W3D_DIR_PATH); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\' && dirBuf[len-1] != '/') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.*", ARRAY_SIZE(findBuf)); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.w3d"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory(TEST_W3D_DIR_PATH, "*.w3d", filenameList, FALSE); if (filenameList.size() > 0) { FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; // only do .w3d files @@ -310,8 +298,8 @@ BOOL ObjectOptions::OnInitDialog() } strcpy(fileBuf, TEST_STRING); - strlcat(fileBuf, "/", ARRAY_SIZE(findBuf)); - strlcat(fileBuf, token.str(), ARRAY_SIZE(findBuf)); + strlcat(fileBuf, "/", ARRAY_SIZE(fileBuf)); + strlcat(fileBuf, token.str(), ARRAY_SIZE(fileBuf)); for (i=strlen(fileBuf)-1; i>0; i--) { if (fileBuf[i] == '.') { // strip off .w3d file extension. @@ -480,8 +468,7 @@ void ObjectOptions::addObject( MapObject *mapObject, const char *pPath, // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/Generals/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp b/Generals/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp index e1047940cc..4868389506 100644 --- a/Generals/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp @@ -307,8 +307,7 @@ void PickUnitDialog::addObject( MapObject *mapObject, const char *pPath, Int ind // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/Generals/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp b/Generals/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp index 375f5fb696..f1819af44a 100644 --- a/Generals/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp @@ -73,21 +73,10 @@ BOOL SelectMacrotexture::OnInitDialog() m_textureTreeView.ShowWindow(SW_SHOW); { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; - strcpy(dirBuf, "..\\Art\\TestModelsHere"); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(findBuf), AsciiString("*.tga"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory("..\\TestArt\\", "*.tga", filenameList, FALSE); if (filenameList.size() > 0) { TVINSERTSTRUCT ins; @@ -95,7 +84,7 @@ BOOL SelectMacrotexture::OnInitDialog() FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; strcpy(fileBuf, filename.str()); ::memset(&ins, 0, sizeof(ins)); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp index acfe4e3aa3..5b6bd01a26 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp @@ -847,14 +847,13 @@ static AsciiString getMapLeafAndDirName(const AsciiString& in) // ------------------------------------------------------------------------------------------------ static AsciiString removeExtension(const AsciiString& in) { - char buf[1024]; - strcpy(buf, in.str()); - char* p = strrchr(buf, '.'); - if (p) + if (const char* end = in.reverseFind('.')) { - *p = 0; + const char* begin = in.str(); + return AsciiString(begin, end - begin); } - return AsciiString(buf); + + return in; } // ------------------------------------------------------------------------------------------------ @@ -1619,22 +1618,16 @@ void GameState::xfer( Xfer *xfer ) saveGameInfo->mapLabel = dict->getAsciiString( TheKey_mapName, &exists ); // if no label was found, we'll use the map name (just filename, no directory info) - if( exists == FALSE || saveGameInfo->mapLabel == AsciiString::TheEmptyString ) + if (exists == FALSE || saveGameInfo->mapLabel == AsciiString::TheEmptyString) { - char string[ _MAX_PATH ]; - - strcpy( string, TheGlobalData->m_mapName.str() ); - char *p = strrchr( string, '\\' ); - if( p == NULL ) + const char* p = TheGlobalData->m_mapName.reverseFind('\\'); + if (p == NULL) saveGameInfo->mapLabel = TheGlobalData->m_mapName; else { - p++; // skip the '\' we're on - saveGameInfo->mapLabel.set( p ); - + saveGameInfo->mapLabel.set(p); } - } // xfer map label diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp index 75900159d6..bb8190edd9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp @@ -219,11 +219,9 @@ void JoinDirectConnectGame() AsciiString ipstring; asciientry.nextToken(&ipstring, "("); - char ipstr[16]; - strcpy(ipstr, ipstring.str()); - Int ip1, ip2, ip3, ip4; - sscanf(ipstr, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4); + Int numFields = sscanf(ipstring.str(), "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4); + (void)numFields; DEBUG_ASSERTCRASH(numFields == 4, ("JoinDirectConnectGame - invalid IP address format: %s", ipstring.str())); DEBUG_LOG(("JoinDirectConnectGame - joining at %d.%d.%d.%d", ip1, ip2, ip3, ip4)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp index 0967db847b..7bbe1d9024 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp @@ -2627,11 +2627,10 @@ void ScriptActions::doDisplayCinematicText(const AsciiString& displayText, const // get the font name AsciiString fontName = AsciiString::TheEmptyString; - char buf[256]; - char *c; - strcpy(buf, fontType.str()); + // TheSuperHackers @fix xezon 16/03/2025 Fixes potential buffer overrun via prior c!='\0' test. - for( c = buf; *c != '\0'; c++ ) + const char* c = fontType.str(); + for (; *c != '\0'; c++) { if( *c != ' ' && *c++ != '-' ) fontName.concat(c); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp index 7cef7ea437..7412dc2a74 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp @@ -679,9 +679,7 @@ Bool FirewallHelperClass::detectionBeginUpdate() { /* ** Do the lookup. */ - char temp_name[256]; - strcpy(temp_name, mangler_name_ptr); - struct hostent *host_info = gethostbyname(temp_name); + struct hostent *host_info = gethostbyname(mangler_name_ptr); if (!host_info) { DEBUG_LOG(("gethostbyname failed! Error code %d", WSAGetLastError())); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp index 58dc8a3cd5..d6f6cf98c1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp @@ -127,15 +127,12 @@ UDP::~UDP() Int UDP::Bind(const char *Host,UnsignedShort port) { - char hostName[100]; struct hostent *hostStruct; struct in_addr *hostNode; if (isdigit(Host[0])) return ( Bind( ntohl(inet_addr(Host)), port) ); - strcpy(hostName, Host); - hostStruct = gethostbyname(Host); if (hostStruct == NULL) return (0); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp index eae8ffc250..4ea3553eb7 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp @@ -277,14 +277,12 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_W3D ) { sprintf(m_filePath,USER_W3D_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_W3D_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } else if( isImageFileType(fileType) ) { sprintf(m_filePath,USER_TGA_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_TGA_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } @@ -301,7 +299,6 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_TGA ) // just TGA, since we don't do dds previews { sprintf(m_filePath,MAP_PREVIEW_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_TGA_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp index 35b3c12824..e65d5f7c5a 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp @@ -117,22 +117,6 @@ Bool W3DTerrainLogic::loadMap( AsciiString filename , Bool query ) WorldHeightMap *terrainHeightMap; ///< holds raw heightmap data samples - char tempBuf[_MAX_PATH]; - char filenameBuf[_MAX_PATH]; - int length = 0; - - strcpy(tempBuf, filename.str()); - - length = strlen( tempBuf ); - if( length >= 4 ) - { - strlcpy( filenameBuf, tempBuf, length - 4 + 1); - } - -// const char *fname = filename.reverseFind('\\'); -// if (fname) -// filename = fname+1; - CachedFileInputStream fileStrm; if ( !fileStrm.open(filename) ) { diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp index 3c842f751d..99e40f1f48 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp @@ -3539,7 +3539,6 @@ void GUIEdit::stripNameDecorations( GameWindow *root ) if( !instData->m_decoratedNameString.isEmpty() ) { - char nameOnly[ MAX_WINDOW_NAME_LEN ]; const char *c; // skip past the "filename.wnd:" to the name only @@ -3550,11 +3549,8 @@ void GUIEdit::stripNameDecorations( GameWindow *root ) // skip beyong the scope resolution colon c++; - // copy the name - strcpy( nameOnly, c ); - // put the name only in the decoration field - instData->m_decoratedNameString = nameOnly; + instData->m_decoratedNameString = c; } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp index 2db5faf7b9..3cd3f55681 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp @@ -207,10 +207,6 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare // Int availableTiles = 4 * tilesPerRow * tilesPerRow; // Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles; - char label[_MAX_PATH]; - snprintf(label, ARRAY_SIZE(label), "%s", buffer); - - if( doAdd ) { TVINSERTSTRUCT ins; @@ -220,8 +216,8 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare ins.hInsertAfter = TVI_LAST; ins.item.mask = TVIF_PARAM|TVIF_TEXT; ins.item.lParam = terrainNdx; - ins.item.pszText = label; - ins.item.cchTextMax = strlen(label)+2; + ins.item.pszText = buffer; + ins.item.cchTextMax = strlen(buffer)+2; m_terrainTreeView.InsertItem(&ins); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp index 3bdd2bc0aa..99ff8ccd63 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -737,24 +737,20 @@ void BuildList::OnExport() static FILE *theLogFile = NULL; Bool open = false; try { - char dirbuf[ _MAX_PATH ]; - ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - if (char *pEnd = strrchr(dirbuf, '\\')) + char buffer[_MAX_PATH]; + ::GetModuleFileName(NULL, buffer, sizeof(buffer)); + if (char* pEnd = strrchr(buffer, '\\')) { *(pEnd + 1) = 0; } - char curbuf[ _MAX_PATH ]; - - strcpy(curbuf, dirbuf); - SidesInfo *pSide = TheSidesList->getSideInfo(m_curSide); - Dict *d = TheSidesList->getSideInfo(m_curSide)->getDict(); + SidesInfo* pSide = TheSidesList->getSideInfo(m_curSide); + Dict* d = TheSidesList->getSideInfo(m_curSide)->getDict(); AsciiString name = d->getAsciiString(TheKey_playerName); - strlcat(curbuf, name.str(), ARRAY_SIZE(curbuf)); - strlcat(curbuf, "_BuildList", ARRAY_SIZE(curbuf)); - strlcat(curbuf, ".ini", ARRAY_SIZE(curbuf)); + strlcat(buffer, name.str(), ARRAY_SIZE(buffer)); + strlcat(buffer, "_BuildList.ini", ARRAY_SIZE(buffer)); - theLogFile = fopen(curbuf, "w"); + theLogFile = fopen(buffer, "w"); if (theLogFile == NULL) throw; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp index 25af1e3b6e..4612838395 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp @@ -100,7 +100,6 @@ BOOL EditObjectParameter::OnInitDialog() //------------------------------------------------------------------------------------------------- void EditObjectParameter::addObject( const ThingTemplate *thingTemplate ) { - char buffer[ _MAX_PATH ]; HTREEITEM parent = TVI_ROOT; const char *leafName; // @@ -121,8 +120,7 @@ void EditObjectParameter::addObject( const ThingTemplate *thingTemplate ) // first sort by Side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH(!side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp index b4fcc6e734..c49e0a24b6 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp @@ -236,7 +236,6 @@ HTREEITEM FenceOptions::findOrAdd(HTREEITEM parent, const char *pLabel) void FenceOptions::addObject( MapObject *mapObject, const char *pPath, const char *name, Int terrainNdx, HTREEITEM parent ) { - char buffer[ _MAX_PATH ]; const char *leafName = NULL; // sanity @@ -262,8 +261,7 @@ void FenceOptions::addObject( MapObject *mapObject, const char *pPath, const cha // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp index 6e1e94fb7e..965ad627e5 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp @@ -80,23 +80,11 @@ BOOL MeshMoldOptions::OnInitDialog() m_moldTreeView.ShowWindow(SW_SHOW); { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; Int i; - strcpy(dirBuf, ".\\data\\Editor\\Molds"); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.w3d", ARRAY_SIZE(findBuf)); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.w3d"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory(".\\data\\Editor\\Molds\\", "*.w3d", filenameList, FALSE); if (filenameList.size() > 0) { HTREEITEM child = NULL; @@ -104,7 +92,7 @@ BOOL MeshMoldOptions::OnInitDialog() do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; strcpy(fileBuf, filename.str()); for (i=strlen(fileBuf)-1; i>0; i--) { diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp index f7e5b7e471..cbb6f666df 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp @@ -277,29 +277,17 @@ BOOL ObjectOptions::OnInitDialog() #endif #ifdef LOAD_TEST_ASSETS { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; Int i; - strcpy(dirBuf, TEST_W3D_DIR_PATH); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\' && dirBuf[len-1] != '/') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.*", ARRAY_SIZE(findBuf)); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.w3d"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory(TEST_W3D_DIR_PATH, "*.w3d", filenameList, FALSE); if (filenameList.size() > 0) { FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; // only do .w3d files @@ -310,8 +298,8 @@ BOOL ObjectOptions::OnInitDialog() } strcpy(fileBuf, TEST_STRING); - strlcat(fileBuf, "/", ARRAY_SIZE(findBuf)); - strlcat(fileBuf, token.str(), ARRAY_SIZE(findBuf)); + strlcat(fileBuf, "/", ARRAY_SIZE(fileBuf)); + strlcat(fileBuf, token.str(), ARRAY_SIZE(fileBuf)); for (i=strlen(fileBuf)-1; i>0; i--) { if (fileBuf[i] == '.') { // strip off .w3d file extension. @@ -480,8 +468,7 @@ void ObjectOptions::addObject( MapObject *mapObject, const char *pPath, // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp index 754dd298bb..af43ef583b 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp @@ -307,8 +307,7 @@ void PickUnitDialog::addObject( MapObject *mapObject, const char *pPath, Int ind // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp index 5867d6588a..b8d347083a 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp @@ -73,21 +73,10 @@ BOOL SelectMacrotexture::OnInitDialog() m_textureTreeView.ShowWindow(SW_SHOW); { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; - strcpy(dirBuf, "..\\TestArt"); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(findBuf), AsciiString("*.tga"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory("..\\TestArt\\", "*.tga", filenameList, FALSE); if (filenameList.size() > 0) { TVINSERTSTRUCT ins; @@ -95,7 +84,7 @@ BOOL SelectMacrotexture::OnInitDialog() FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; strcpy(fileBuf, filename.str()); ::memset(&ins, 0, sizeof(ins)); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 972c676027..59c6348146 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -434,7 +434,6 @@ void WorldHeightMapEdit::loadDirectoryOfImages(const char *pFilePath) FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - //strcpy(fileBuf, dirBuf); strlcpy(fileBuf, filename.str(), ARRAY_SIZE(fileBuf)); loadBitmap(fileBuf, filename.str());