Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
3 changes: 0 additions & 3 deletions Generals/Code/GameEngine/Source/GameNetwork/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

}
Expand All @@ -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));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) )
{
Expand Down
6 changes: 1 addition & 5 deletions Generals/Code/Tools/GUIEdit/Source/GUIEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

}

Expand Down
8 changes: 2 additions & 6 deletions Generals/Code/Tools/WorldBuilder/src/BlendMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
16 changes: 6 additions & 10 deletions Generals/Code/Tools/WorldBuilder/src/BuildList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions Generals/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ BOOL EditObjectParameter::OnInitDialog()
//-------------------------------------------------------------------------------------------------
void EditObjectParameter::addObject( const ThingTemplate *thingTemplate )
{
char buffer[ _MAX_PATH ];
HTREEITEM parent = TVI_ROOT;
const char *leafName;
//
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions Generals/Code/Tools/WorldBuilder/src/FenceOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
16 changes: 2 additions & 14 deletions Generals/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,19 @@ 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;
FilenameList::iterator it = filenameList.begin();
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--) {
Expand Down
23 changes: 5 additions & 18 deletions Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions Generals/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 2 additions & 13 deletions Generals/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,18 @@ 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;
HTREEITEM child = NULL;
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));
Expand Down
Loading
Loading