[6894] Backport file name preparing code in VMapManager from 303 branch that fix also possible memory corruption.

This commit is contained in:
VladimirMangos 2008-12-10 19:24:15 +03:00
parent 477ba70782
commit 467090e817
2 changed files with 7 additions and 13 deletions

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "6893"
#define REVISION_NR "6894"
#endif // __REVISION_NR_H__

View file

@ -275,10 +275,8 @@ namespace VMAP
{
dirFileName = getDirFileName(pMapId);
}
size_t len = pBasePath.length() + dirFileName.length();
char *filenameBuffer = new char[len+1];
sprintf(filenameBuffer, "%s%s", pBasePath.c_str(), dirFileName.c_str());
FILE* df = fopen(filenameBuffer, "rb");
std::string fb = pBasePath + dirFileName;
FILE* df = fopen(fb.c_str(), "rb");
if(df)
{
char lineBuffer[FILENAMEBUFFER_SIZE];
@ -288,8 +286,8 @@ namespace VMAP
chomp(name);
if(name.length() >1)
{
sprintf(filenameBuffer, "%s%s", pBasePath.c_str(), name.c_str());
FILE* df2 = fopen(filenameBuffer, "rb");
std::string fb2 = pBasePath + name;
FILE* df2 = fopen(fb2.c_str(), "rb");
if(df2)
{
char magic[8];
@ -302,7 +300,6 @@ namespace VMAP
}
fclose(df);
}
delete[] filenameBuffer;
return result;
}
@ -659,14 +656,12 @@ namespace VMAP
bool MapTree::loadMap(const std::string& pDirFileName, unsigned int pMapTileIdent)
{
bool result = true;
size_t len = iBasePath.length() + pDirFileName.length();
char *filenameBuffer = new char[len+1];
if(!hasDirFile(pDirFileName))
{
FilesInDir filesInDir;
result = false;
sprintf(filenameBuffer, "%s%s", iBasePath.c_str(), pDirFileName.c_str());
FILE* df = fopen(filenameBuffer, "rb");
std::string fb = iBasePath + pDirFileName;
FILE* df = fopen(fb.c_str(), "rb");
if(df)
{
char lineBuffer[FILENAMEBUFFER_SIZE];
@ -726,7 +721,6 @@ namespace VMAP
filesInDir.incRefCount();
}
}
delete [] filenameBuffer;
return (result);
}