aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-03-01 16:05:34 +0100
committerShauren <shauren.trinity@gmail.com>2025-08-30 22:55:20 +0200
commit7e193e15dbaf6429b93ec9f0bea099f1fb90ff05 (patch)
tree4e574f8c3de561798f53179b9080cdb4d4f3a71c
parent290a7b93107b4864f5aad57b415c9237922e3379 (diff)
Core/Misc: Replace sprintf with safer alternatives (Trinity::StringFormat or snprintf)
(cherry picked from commit 67244a1f70273e20801b2ae668603af81d72d602)
-rw-r--r--src/common/Debugging/WheatyExceptionReport.cpp46
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp8
-rw-r--r--src/tools/mmaps_generator/IntermediateValues.cpp81
-rw-r--r--src/tools/mmaps_generator/MapBuilder.cpp23
-rw-r--r--src/tools/mmaps_generator/TerrainBuilder.cpp8
-rw-r--r--src/tools/vmap4_extractor/model.cpp33
-rw-r--r--src/tools/vmap4_extractor/vmapexport.cpp11
-rw-r--r--src/tools/vmap4_extractor/wmo.cpp16
8 files changed, 92 insertions, 134 deletions
diff --git a/src/common/Debugging/WheatyExceptionReport.cpp b/src/common/Debugging/WheatyExceptionReport.cpp
index b88b510fbbb..00d168efd71 100644
--- a/src/common/Debugging/WheatyExceptionReport.cpp
+++ b/src/common/Debugging/WheatyExceptionReport.cpp
@@ -42,7 +42,7 @@ inline LPTSTR ErrorMessage(DWORD dw)
else
{
LPTSTR msgBuf = (LPTSTR)LocalAlloc(LPTR, 30);
- sprintf(msgBuf, "Unknown error: %u", dw);
+ snprintf(msgBuf, 30, "Unknown error: %u", dw);
return msgBuf;
}
@@ -122,7 +122,7 @@ PEXCEPTION_POINTERS pExceptionInfo)
++pos;
TCHAR crash_folder_path[MAX_PATH];
- sprintf_s(crash_folder_path, "%s\\%s", module_folder_name, CrashFolder);
+ _stprintf_s(crash_folder_path, "%s\\%s", module_folder_name, CrashFolder);
if (!CreateDirectory(crash_folder_path, nullptr))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
@@ -131,10 +131,10 @@ PEXCEPTION_POINTERS pExceptionInfo)
SYSTEMTIME systime;
GetLocalTime(&systime);
- sprintf(m_szDumpFileName, "%s\\%s_%s_[%u-%u_%u-%u-%u].dmp",
+ _stprintf_s(m_szDumpFileName, "%s\\%s_%s_[%u-%u_%u-%u-%u].dmp",
crash_folder_path, GitRevision::GetHash(), pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);
- _stprintf(m_szLogFileName, _T("%s\\%s_%s_[%u-%u_%u-%u-%u].txt"),
+ _stprintf_s(m_szLogFileName, _T("%s\\%s_%s_[%u-%u_%u-%u-%u].txt"),
crash_folder_path, GitRevision::GetHash(), pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);
m_hDumpFile = CreateFile(m_szDumpFileName,
@@ -372,13 +372,13 @@ BOOL WheatyExceptionReport::_GetWindowsVersion(TCHAR* szVersion, DWORD cntMax)
lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"), 0, KEY_QUERY_VALUE, &hKey);
if (lRet == ERROR_SUCCESS)
{
- _stprintf(wszTmp, _T("Service Pack 6a (Version %d.%d, Build %d)"),
+ _stprintf_s(wszTmp, _T("Service Pack 6a (Version %d.%d, Build %d)"),
osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
_tcsncat(szVersion, wszTmp, cntMax);
}
else // Windows NT 4.0 prior to SP6a
{
- _stprintf(wszTmp, _T("%s (Version %d.%d, Build %d)"),
+ _stprintf_s(wszTmp, _T("%s (Version %d.%d, Build %d)"),
szCSDVersion, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
_tcsncat(szVersion, wszTmp, cntMax);
}
@@ -387,17 +387,17 @@ BOOL WheatyExceptionReport::_GetWindowsVersion(TCHAR* szVersion, DWORD cntMax)
else // Windows NT 3.51 and earlier or Windows 2000 and later
{
if (!_tcslen(szCSDVersion))
- _stprintf(wszTmp, _T("(Version %d.%d, Build %d)"),
+ _stprintf_s(wszTmp, _T("(Version %d.%d, Build %d)"),
osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
else
- _stprintf(wszTmp, _T("%s (Version %d.%d, Build %d)"),
+ _stprintf_s(wszTmp, _T("%s (Version %d.%d, Build %d)"),
szCSDVersion, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
_tcsncat(szVersion, wszTmp, cntMax);
}
break;
}
default:
- _stprintf(wszTmp, _T("%s (Version %d.%d, Build %d)"),
+ _stprintf_s(wszTmp, _T("%s (Version %d.%d, Build %d)"),
szCSDVersion, osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
_tcsncat(szVersion, wszTmp, cntMax);
break;
@@ -1733,50 +1733,50 @@ size_t countOverride)
else
length = strlen((char*)pAddress);
if (length > bufferSize - 6)
- pszCurrBuffer += sprintf(pszCurrBuffer, "\"%.*s...\"", (DWORD)(bufferSize - 6), (char*)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "\"%.*s...\"", (int)(bufferSize - 6), (char*)pAddress);
else
- pszCurrBuffer += sprintf(pszCurrBuffer, "\"%.*s\"", (DWORD)length, (char*)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "\"%.*s\"", (int)length, (char*)pAddress);
break;
}
case btStdString:
{
std::string* value = static_cast<std::string*>(pAddress);
if (value->length() > bufferSize - 6)
- pszCurrBuffer += sprintf(pszCurrBuffer, "\"%.*s...\"", (DWORD)(bufferSize - 6), value->c_str());
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "\"%.*s...\"", (int)(bufferSize - 6), value->c_str());
else
- pszCurrBuffer += sprintf(pszCurrBuffer, "\"%s\"", value->c_str());
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "\"%s\"", value->c_str());
break;
}
default:
// Format appropriately (assuming it's a 1, 2, or 4 bytes (!!!)
if (length == 1)
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%X", *(PBYTE)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%X", *(PBYTE)pAddress);
else if (length == 2)
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%X", *(PWORD)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%X", *(PWORD)pAddress);
else if (length == 4)
{
if (basicType == btFloat)
- pszCurrBuffer += sprintf(pszCurrBuffer, "%f", *(PFLOAT)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "%f", *(PFLOAT)pAddress);
else
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%X", *(PDWORD)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%X", *(PDWORD)pAddress);
}
else if (length == 8)
{
if (basicType == btFloat)
{
- pszCurrBuffer += sprintf(pszCurrBuffer, "%f",
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "%f",
*(double *)pAddress);
}
else
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%I64X",
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%I64X",
*(DWORD64*)pAddress);
}
else
{
#if _WIN64
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%I64X", (DWORD64)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%I64X", (DWORD64)pAddress);
#else
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%X", (DWORD)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%X", (DWORD)pAddress);
#endif
}
break;
@@ -1785,9 +1785,9 @@ size_t countOverride)
__except (EXCEPTION_EXECUTE_HANDLER)
{
#if _WIN64
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%I64X <Unable to read memory>", (DWORD64)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%I64X <Unable to read memory>", (DWORD64)pAddress);
#else
- pszCurrBuffer += sprintf(pszCurrBuffer, "0x%X <Unable to read memory>", (DWORD)pAddress);
+ pszCurrBuffer += snprintf(pszCurrBuffer, bufferSize, "0x%X <Unable to read memory>", (DWORD)pAddress);
#endif
}
}
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 75d62371c1c..747f0aa1330 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -123,9 +123,7 @@ std::string GetScriptCommandName(ScriptCommands command)
case SCRIPT_COMMAND_MOVEMENT: res = "SCRIPT_COMMAND_MOVEMENT"; break;
default:
{
- char sz[32];
- sprintf(sz, "Unknown command: %d", command);
- res = sz;
+ res = Trinity::StringFormat("Unknown command: {}", command);
break;
}
}
@@ -134,9 +132,7 @@ std::string GetScriptCommandName(ScriptCommands command)
std::string ScriptInfo::GetDebugInfo() const
{
- char sz[256];
- sprintf(sz, "%s ('%s' script id: %u)", GetScriptCommandName(command).c_str(), GetScriptsTableNameByType(type).c_str(), id);
- return std::string(sz);
+ return Trinity::StringFormat("{} ('{}' script id: {})", GetScriptCommandName(command), GetScriptsTableNameByType(type), id);
}
bool normalizePlayerName(std::string& name)
diff --git a/src/tools/mmaps_generator/IntermediateValues.cpp b/src/tools/mmaps_generator/IntermediateValues.cpp
index 633e4de80e0..9e82c793320 100644
--- a/src/tools/mmaps_generator/IntermediateValues.cpp
+++ b/src/tools/mmaps_generator/IntermediateValues.cpp
@@ -16,6 +16,7 @@
*/
#include "IntermediateValues.h"
+#include "StringFormat.h"
namespace MMAP
{
@@ -30,42 +31,32 @@ namespace MMAP
void IntermediateValues::writeIV(uint32 mapID, uint32 tileX, uint32 tileY)
{
- char fileName[255];
- char tileString[25];
- sprintf(tileString, "[%02u,%02u]: ", tileX, tileY);
-
- printf("%sWriting debug output... \r", tileString);
-
- std::string name("meshes/%03u%02i%02i.");
-
-#define DEBUG_WRITE(fileExtension,data) \
- do { \
- sprintf(fileName, (name + fileExtension).c_str(), mapID, tileY, tileX); \
- FILE* file = fopen(fileName, "wb"); \
- if (!file) \
- { \
- char message[1024]; \
- sprintf(message, "%sFailed to open %s for writing!\n", tileString, fileName); \
- perror(message); \
- } \
- else \
- debugWrite(file, data); \
- if (file) fclose(file); \
- printf("%sWriting debug output... \r", tileString); \
- } while (false)
+ std::string tileString = Trinity::StringFormat("[{:02},{:02}]: ", tileX, tileY);
+
+ printf("%sWriting debug output... \r", tileString.c_str());
+
+ auto debugWrite = [&](char const* extension, auto const* data)
+ {
+ std::string fileName = Trinity::StringFormat("meshes/{:03}{:02}{:02}.{}", mapID, tileY, tileX, extension);
+ if (FILE* file = fopen(fileName.c_str(), "wb"))
+ {
+ this->debugWrite(file, data);
+ fclose(file);
+ }
+ else
+ perror(Trinity::StringFormat("{}Failed to open {} for writing!\n", tileString, fileName).c_str());
+ };
if (heightfield)
- DEBUG_WRITE("hf", heightfield);
+ debugWrite("hf", heightfield);
if (compactHeightfield)
- DEBUG_WRITE("chf", compactHeightfield);
+ debugWrite("chf", compactHeightfield);
if (contours)
- DEBUG_WRITE("cs", contours);
+ debugWrite("cs", contours);
if (polyMesh)
- DEBUG_WRITE("pmesh", polyMesh);
+ debugWrite("pmesh", polyMesh);
if (polyMeshDetail)
- DEBUG_WRITE("dmesh", polyMeshDetail);
-
-#undef DEBUG_WRITE
+ debugWrite("dmesh", polyMeshDetail);
}
void IntermediateValues::debugWrite(FILE* file, rcHeightfield const* mesh)
@@ -200,15 +191,13 @@ namespace MMAP
void IntermediateValues::generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
{
- char objFileName[255];
- sprintf(objFileName, "meshes/map%03u%02u%02u.obj", mapID, tileY, tileX);
+ std::string objFileName;
+ objFileName = Trinity::StringFormat("meshes/map{:03}{:02}{:02}.obj", mapID, tileY, tileX);
- FILE* objFile = fopen(objFileName, "wb");
+ FILE* objFile = fopen(objFileName.c_str(), "wb");
if (!objFile)
{
- char message[1024];
- sprintf(message, "Failed to open %s for writing!\n", objFileName);
- perror(message);
+ perror(Trinity::StringFormat("Failed to open {} for writing!\n", objFileName).c_str());
return;
}
@@ -233,18 +222,14 @@ namespace MMAP
fclose(objFile);
- char tileString[25];
- sprintf(tileString, "[%02u,%02u]: ", tileY, tileX);
- printf("%sWriting debug output... \r", tileString);
+ printf("[%02u,%02u]: Writing debug output... \r", tileY, tileX);
- sprintf(objFileName, "meshes/%03u.map", mapID);
+ objFileName = Trinity::StringFormat("meshes/map{:03}.map", mapID);
- objFile = fopen(objFileName, "wb");
+ objFile = fopen(objFileName.c_str(), "wb");
if (!objFile)
{
- char message[1024];
- sprintf(message, "Failed to open %s for writing!\n", objFileName);
- perror(message);
+ perror(Trinity::StringFormat("Failed to open {} for writing!\n", objFileName).c_str());
return;
}
@@ -252,13 +237,11 @@ namespace MMAP
fwrite(&b, sizeof(char), 1, objFile);
fclose(objFile);
- sprintf(objFileName, "meshes/%03u%02u%02u.mesh", mapID, tileY, tileX);
- objFile = fopen(objFileName, "wb");
+ objFileName = Trinity::StringFormat("meshes/map{:03}{:02}{:02}.mesh", mapID, tileY, tileX);
+ objFile = fopen(objFileName.c_str(), "wb");
if (!objFile)
{
- char message[1024];
- sprintf(message, "Failed to open %s for writing!\n", objFileName);
- perror(message);
+ perror(Trinity::StringFormat("Failed to open {} for writing!\n", objFileName).c_str());
return;
}
diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp
index 274ea10bca6..beb708df9ac 100644
--- a/src/tools/mmaps_generator/MapBuilder.cpp
+++ b/src/tools/mmaps_generator/MapBuilder.cpp
@@ -576,16 +576,13 @@ namespace MMAP
return;
}
- char fileName[25];
- sprintf(fileName, "mmaps/%03u.mmap", mapID);
+ std::string fileName = Trinity::StringFormat("mmaps/{:03}.mmap", mapID);
- FILE* file = fopen(fileName, "wb");
+ FILE* file = fopen(fileName.c_str(), "wb");
if (!file)
{
dtFreeNavMesh(navMesh);
- char message[1024];
- sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName);
- perror(message);
+ perror(Trinity::StringFormat("[Map {:03}] Failed to open {} for writing!\n", mapID, fileName).c_str());
return;
}
@@ -890,14 +887,11 @@ namespace MMAP
}
// file output
- char fileName[255];
- sprintf(fileName, "mmaps/%03u%02i%02i.mmtile", mapID, tileY, tileX);
- FILE* file = fopen(fileName, "wb");
+ std::string fileName = Trinity::StringFormat("mmaps/{:03}{:02}{:02}.mmtile", mapID, tileY, tileX);
+ FILE* file = fopen(fileName.c_str(), "wb");
if (!file)
{
- char message[1024];
- sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName);
- perror(message);
+ perror(Trinity::StringFormat("[Map {:03}] Failed to open {} for writing!\n", mapID, fileName).c_str());
navMesh->removeTile(tileRef, nullptr, nullptr);
break;
}
@@ -1063,9 +1057,8 @@ namespace MMAP
/**************************************************************************/
bool TileBuilder::shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY) const
{
- char fileName[255];
- sprintf(fileName, "mmaps/%03u%02i%02i.mmtile", mapID, tileY, tileX);
- FILE* file = fopen(fileName, "rb");
+ std::string fileName = Trinity::StringFormat("mmaps/{:03}{:02}{:02}.mmtile", mapID, tileY, tileX);
+ FILE* file = fopen(fileName.c_str(), "rb");
if (!file)
return false;
diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp
index c9743d229ac..9da006f813c 100644
--- a/src/tools/mmaps_generator/TerrainBuilder.cpp
+++ b/src/tools/mmaps_generator/TerrainBuilder.cpp
@@ -21,6 +21,7 @@
#include "MapDefines.h"
#include "MapTree.h"
#include "ModelInstance.h"
+#include "StringFormat.h"
#include "VMapFactory.h"
#include "VMapManager2.h"
#include <map>
@@ -135,10 +136,9 @@ namespace MMAP
/**************************************************************************/
bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, Spot portion)
{
- char mapFileName[255];
- sprintf(mapFileName, "maps/%03u%02u%02u.map", mapID, tileY, tileX);
+ std::string mapFileName = Trinity::StringFormat("maps/{:03}{:02}{:02}.map", mapID, tileY, tileX);
- FILE* mapFile = fopen(mapFileName, "rb");
+ FILE* mapFile = fopen(mapFileName.c_str(), "rb");
if (!mapFile)
return false;
@@ -147,7 +147,7 @@ namespace MMAP
fheader.versionMagic != MAP_VERSION_MAGIC)
{
fclose(mapFile);
- printf("%s is the wrong version, please extract new .map files\n", mapFileName);
+ printf("%s is the wrong version, please extract new .map files\n", mapFileName.c_str());
return false;
}
diff --git a/src/tools/vmap4_extractor/model.cpp b/src/tools/vmap4_extractor/model.cpp
index c1271b1c76d..49e812916b3 100644
--- a/src/tools/vmap4_extractor/model.cpp
+++ b/src/tools/vmap4_extractor/model.cpp
@@ -18,6 +18,7 @@
#include "vmapexport.h"
#include "Errors.h"
#include "model.h"
+#include "StringFormat.h"
#include "wmo.h"
#include "adtfile.h"
#include "mpq_libmpq.h"
@@ -140,9 +141,8 @@ Vec3D fixCoordSystem(Vec3D const& v)
void Doodad::Extract(ADT::MDDF const& doodadDef, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile)
{
- char tempname[1036];
- sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
- FILE* input = fopen(tempname, "r+b");
+ std::string tempname = Trinity::StringFormat("{}/{}", szWorkDirWmo, ModelInstName);
+ FILE* input = fopen(tempname.c_str(), "r+b");
if (!input)
return;
@@ -199,24 +199,15 @@ void Doodad::ExtractSet(WMODoodadData const& doodadData, ADT::MODF const& wmo, u
WMO::MODD const& doodad = doodadData.Spawns[doodadIndex];
- char ModelInstName[1024];
- sprintf(ModelInstName, "%s", GetPlainName(&doodadData.Paths[doodad.NameIndex]));
- uint32 nlen = strlen(ModelInstName);
- fixnamen(ModelInstName, nlen);
- fixname2(ModelInstName, nlen);
- if (nlen > 3)
- {
- char const* extension = &ModelInstName[nlen - 4];
- if (!strcmp(extension, ".mdx") || !strcmp(extension, ".mdl"))
- {
- ModelInstName[nlen - 2] = '2';
- ModelInstName[nlen - 1] = '\0';
- }
- }
+ std::string ModelInstName = GetPlainName(&doodadData.Paths[doodad.NameIndex]);
+ uint32 nlen = ModelInstName.length();
+ fixnamen(ModelInstName.data(), nlen);
+ fixname2(ModelInstName.data(), nlen);
+ if (ModelInstName.ends_with(".mdx") || ModelInstName.ends_with(".mdl"))
+ ModelInstName.replace(ModelInstName.length() - 2, 2, "2");
- char tempname[1036];
- sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
- FILE* input = fopen(tempname, "r+b");
+ std::string tempname = Trinity::StringFormat("{}/{}", szWorkDirWmo, ModelInstName);
+ FILE* input = fopen(tempname.c_str(), "r+b");
if (!input)
continue;
@@ -259,6 +250,6 @@ void Doodad::ExtractSet(WMODoodadData const& doodadData, ADT::MODF const& wmo, u
fwrite(&rotation, sizeof(Vec3D), 1, pDirfile);
fwrite(&doodad.Scale, sizeof(float), 1, pDirfile);
fwrite(&nlen, sizeof(uint32), 1, pDirfile);
- fwrite(ModelInstName, sizeof(char), nlen, pDirfile);
+ fwrite(ModelInstName.c_str(), sizeof(char), nlen, pDirfile);
}
}
diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp
index e5a3c04b839..5926f2e525c 100644
--- a/src/tools/vmap4_extractor/vmapexport.cpp
+++ b/src/tools/vmap4_extractor/vmapexport.cpp
@@ -87,13 +87,12 @@ bool ExtractSingleWmo(std::string& fname)
// Copy files from archive
std::string originalName = fname;
- char szLocalFile[1024];
char* plain_name = GetPlainName(&fname[0]);
fixnamen(plain_name, strlen(plain_name));
fixname2(plain_name, strlen(plain_name));
- sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
+ std::string szLocalFile = Trinity::StringFormat("{}/{}", szWorkDirWmo, plain_name);
- if (FileExists(szLocalFile))
+ if (FileExists(szLocalFile.c_str()))
return true;
int p = 0;
@@ -122,10 +121,10 @@ bool ExtractSingleWmo(std::string& fname)
printf("Couldn't open RootWmo!!!\n");
return true;
}
- FILE *output = fopen(szLocalFile,"wb");
+ FILE *output = fopen(szLocalFile.c_str(),"wb");
if(!output)
{
- printf("couldn't open %s for writing!\n", szLocalFile);
+ printf("couldn't open %s for writing!\n", szLocalFile.c_str());
return false;
}
froot.ConvertToVMAPRootWmo(output);
@@ -177,7 +176,7 @@ bool ExtractSingleWmo(std::string& fname)
// Delete the extracted file in the case of an error
if (!file_ok)
- remove(szLocalFile);
+ remove(szLocalFile.c_str());
return true;
}
diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp
index ffb3116014b..4e7e0eb2e2d 100644
--- a/src/tools/vmap4_extractor/wmo.cpp
+++ b/src/tools/vmap4_extractor/wmo.cpp
@@ -17,18 +17,16 @@
#include "vmapexport.h"
#include "adtfile.h"
-#include "vec3d.h"
+#include "Errors.h"
#include "mpq_libmpq.h"
-
+#include "StringFormat.h"
+#include "vec3d.h"
#include "VMapDefinitions.h"
#include "wmo.h"
#include <fstream>
#include <map>
#include <cstdio>
#include <cstdlib>
-#include "Errors.h"
-#undef min
-#undef max
WMORoot::WMORoot(std::string const& filename)
: filename(filename), color(0), nTextures(0), nGroups(0), nPortals(0), nLights(0),
@@ -533,14 +531,12 @@ void MapObject::Extract(ADT::MODF const& mapObjDef, char const* WmoInstName, uin
//-----------add_in _dir_file----------------
- char tempname[512];
- sprintf(tempname, "%s/%s", szWorkDirWmo, WmoInstName);
- FILE *input;
- input = fopen(tempname, "r+b");
+ std::string tempname = Trinity::StringFormat("{}/{}", szWorkDirWmo, WmoInstName);
+ FILE* input = fopen(tempname.c_str(), "r+b");
if (!input)
{
- printf("WMOInstance::WMOInstance: couldn't open %s\n", tempname);
+ printf("WMOInstance::WMOInstance: couldn't open %s\n", tempname.c_str());
return;
}