diff --git a/Generals/Code/Tools/WorldBuilder/src/OpenMap.cpp b/Generals/Code/Tools/WorldBuilder/src/OpenMap.cpp index 8417ad50fc..5810c435c8 100644 --- a/Generals/Code/Tools/WorldBuilder/src/OpenMap.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/OpenMap.cpp @@ -118,21 +118,12 @@ void OpenMap::populateMapListbox( Bool systemMaps ) strcpy(dirBuf, "Maps\\"); else { - strcpy(dirBuf, TheGlobalData->getPath_UserData().str()); - strlcat(dirBuf, "Maps\\", ARRAY_SIZE(dirBuf)); - } - - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; + snprintf(dirBuf, ARRAY_SIZE(dirBuf), "%sMaps\\", TheGlobalData->getPath_UserData().str()); } CListBox *pList = (CListBox *)this->GetDlgItem(IDC_OPEN_LIST); if (pList == NULL) return; pList->ResetContent(); - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.*", ARRAY_SIZE(findBuf)); + snprintf(findBuf, ARRAY_SIZE(findBuf), "%s*.*", dirBuf); Bool found = false; @@ -145,11 +136,7 @@ void OpenMap::populateMapListbox( Bool systemMaps ) continue; } - strcpy(fileBuf, dirBuf); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(findBuf)); - strlcat(fileBuf, "\\", ARRAY_SIZE(findBuf)); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(findBuf)); - strlcat(fileBuf, ".map", ARRAY_SIZE(findBuf)); + snprintf(fileBuf, ARRAY_SIZE(fileBuf), "%s%s\\%s.map", dirBuf, findData.cFileName, findData.cFileName); try { CFileStatus status; if (CFile::GetStatus(fileBuf, status)) { diff --git a/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp b/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp index cc7b029e45..4214f46804 100644 --- a/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/SaveMap.cpp @@ -138,8 +138,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) CListBox *pList = (CListBox *)this->GetDlgItem(IDC_SAVE_LIST); if (pList == NULL) return; pList->ResetContent(); - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.*", ARRAY_SIZE(findBuf)); + snprintf(findBuf, ARRAY_SIZE(findBuf), "%s*.*", dirBuf); hFindFile = FindFirstFile(findBuf, &findData); if (hFindFile != INVALID_HANDLE_VALUE) { @@ -149,11 +148,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { continue; } - strcpy(fileBuf, dirBuf); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(fileBuf)); - strlcat(fileBuf, "\\", ARRAY_SIZE(fileBuf)); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(fileBuf)); - strlcat(fileBuf, ".map", ARRAY_SIZE(fileBuf)); + snprintf(fileBuf, ARRAY_SIZE(fileBuf), "%s%s\\%s.map", dirBuf, findData.cFileName, findData.cFileName); try { CFileStatus status; if (CFile::GetStatus(fileBuf, status)) { @@ -169,7 +164,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) } CEdit *pEdit = (CEdit*)GetDlgItem(IDC_SAVE_MAP_EDIT); if (pEdit != NULL) { - strcpy(fileBuf, m_pInfo->filename); + strlcpy(fileBuf, m_pInfo->filename, ARRAY_SIZE(fileBuf)); Int len = strlen(fileBuf); if (len>4 && stricmp(".map", fileBuf+(len-4)) == 0) { // strip of the .map diff --git a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 2bd85b9c81..c126574eab 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -414,20 +414,18 @@ void WorldHeightMapEdit::loadBaseImages(void) void WorldHeightMapEdit::loadDirectoryOfImages(const char *pFilePath) { char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; - strcpy(dirBuf, pFilePath); + strlcpy(dirBuf, pFilePath, ARRAY_SIZE(dirBuf)); 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("*.*"), filenameList, TRUE); + TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.*"), filenameList, TRUE); if (filenameList.size() == 0) { return; @@ -436,8 +434,7 @@ void WorldHeightMapEdit::loadDirectoryOfImages(const char *pFilePath) do { AsciiString filename = *it; - strcpy(fileBuf, dirBuf); - strcat(fileBuf, filename.str()); + snprintf(fileBuf, ARRAY_SIZE(fileBuf), "%s%s", dirBuf, filename.str()); loadBitmap(fileBuf, filename.str()); ++it; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/OpenMap.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/OpenMap.cpp index 4973d45c5f..9910154332 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/OpenMap.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/OpenMap.cpp @@ -118,21 +118,12 @@ void OpenMap::populateMapListbox( Bool systemMaps ) strcpy(dirBuf, "Maps\\"); else { - strcpy(dirBuf, TheGlobalData->getPath_UserData().str()); - strlcat(dirBuf, "Maps\\", ARRAY_SIZE(dirBuf)); - } - - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; + snprintf(dirBuf, ARRAY_SIZE(dirBuf), "%sMaps\\", TheGlobalData->getPath_UserData().str()); } CListBox *pList = (CListBox *)this->GetDlgItem(IDC_OPEN_LIST); if (pList == NULL) return; pList->ResetContent(); - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.*", ARRAY_SIZE(findBuf)); + snprintf(findBuf, ARRAY_SIZE(findBuf), "%s*.*", dirBuf); Bool found = false; @@ -145,11 +136,7 @@ void OpenMap::populateMapListbox( Bool systemMaps ) continue; } - strcpy(fileBuf, dirBuf); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(findBuf)); - strlcat(fileBuf, "\\", ARRAY_SIZE(findBuf)); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(findBuf)); - strlcat(fileBuf, ".map", ARRAY_SIZE(findBuf)); + snprintf(fileBuf, ARRAY_SIZE(fileBuf), "%s%s\\%s.map", dirBuf, findData.cFileName, findData.cFileName); try { CFileStatus status; if (CFile::GetStatus(fileBuf, status)) { diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp index 99c10f930b..22e6a197c7 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/SaveMap.cpp @@ -138,8 +138,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) CListBox *pList = (CListBox *)this->GetDlgItem(IDC_SAVE_LIST); if (pList == NULL) return; pList->ResetContent(); - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.*", ARRAY_SIZE(findBuf)); + snprintf(findBuf, ARRAY_SIZE(findBuf), "%s*.*", dirBuf); hFindFile = FindFirstFile(findBuf, &findData); if (hFindFile != INVALID_HANDLE_VALUE) { @@ -149,11 +148,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { continue; } - strcpy(fileBuf, dirBuf); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(fileBuf)); - strlcat(fileBuf, "\\", ARRAY_SIZE(fileBuf)); - strlcat(fileBuf, findData.cFileName, ARRAY_SIZE(fileBuf)); - strlcat(fileBuf, ".map", ARRAY_SIZE(fileBuf)); + snprintf(fileBuf, ARRAY_SIZE(fileBuf), "%s%s\\%s.map", dirBuf, findData.cFileName, findData.cFileName); try { CFileStatus status; if (CFile::GetStatus(fileBuf, status)) { @@ -169,7 +164,7 @@ void SaveMap::populateMapListbox( Bool systemMaps ) } CEdit *pEdit = (CEdit*)GetDlgItem(IDC_SAVE_MAP_EDIT); if (pEdit != NULL) { - strcpy(fileBuf, m_pInfo->filename); + strlcpy(fileBuf, m_pInfo->filename, ARRAY_SIZE(fileBuf)); Int len = strlen(fileBuf); if (len>4 && stricmp(".map", fileBuf+(len-4)) == 0) { // strip of the .map diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index e81bf7af7d..972c676027 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -415,20 +415,18 @@ void WorldHeightMapEdit::loadBaseImages(void) void WorldHeightMapEdit::loadDirectoryOfImages(const char *pFilePath) { char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; - strcpy(dirBuf, pFilePath); + strlcpy(dirBuf, pFilePath, ARRAY_SIZE(dirBuf)); 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("*.*"), filenameList, TRUE); + TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.*"), filenameList, TRUE); if (filenameList.size() == 0) { return; @@ -437,7 +435,7 @@ void WorldHeightMapEdit::loadDirectoryOfImages(const char *pFilePath) do { AsciiString filename = *it; //strcpy(fileBuf, dirBuf); - strcpy(fileBuf, filename.str()); + strlcpy(fileBuf, filename.str(), ARRAY_SIZE(fileBuf)); loadBitmap(fileBuf, filename.str()); ++it;