diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-28 20:20:54 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-28 23:25:13 +0300 |
commit | 75a5173176adfc4bc417c10df137d9ea8d90d403 (patch) | |
tree | 2d095e72f084ff96ee5ce3608453d98da0eda5d7 /src/fs | |
parent | b6831b3b3053b1777402a35d8b3ae3cca2f62bc4 (diff) | |
download | manaverse-75a5173176adfc4bc417c10df137d9ea8d90d403.tar.gz manaverse-75a5173176adfc4bc417c10df137d9ea8d90d403.tar.bz2 manaverse-75a5173176adfc4bc417c10df137d9ea8d90d403.tar.xz manaverse-75a5173176adfc4bc417c10df137d9ea8d90d403.zip |
Change memory allocation in Virtfs::LoadFile from calloc to new.
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/files.cpp | 4 | ||||
-rw-r--r-- | src/fs/virtfs/virtfstools.cpp | 16 | ||||
-rw-r--r-- | src/fs/virtfs/virtfstools.h | 2 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/fs/files.cpp b/src/fs/files.cpp index 91433e287..fa9fe2de3 100644 --- a/src/fs/files.cpp +++ b/src/fs/files.cpp @@ -91,11 +91,11 @@ void Files::copyVirtFsFile(const std::string &restrict inFile, const std::string &restrict outFile) { int size = 0; - void *const buf = VirtFs::loadFile(inFile, size); + char *const buf = VirtFs::loadFile(inFile, size); FILE *const file = fopen(outFile.c_str(), "w"); fwrite(buf, 1, size, file); fclose(file); - free(buf); + delete [] buf; #ifdef ANDROID if (mCallbackPtr) { diff --git a/src/fs/virtfs/virtfstools.cpp b/src/fs/virtfs/virtfstools.cpp index 957b73e6e..c58f41b43 100644 --- a/src/fs/virtfs/virtfstools.cpp +++ b/src/fs/virtfs/virtfstools.cpp @@ -36,7 +36,7 @@ namespace VirtFs { - void *loadFile(const std::string &restrict fileName, + char *loadFile(const std::string &restrict fileName, int &restrict fileSize) { // Attempt to open the specified file using PhysicsFS @@ -55,7 +55,9 @@ namespace VirtFs fileSize = CAST_S32(VirtFs::fileLength(file)); // Allocate memory and load the file - void *restrict const buffer = calloc(fileSize, 1); + char *restrict const buffer = new char[fileSize]; + if (fileSize > 0) + buffer[fileSize - 1] = 0; VirtFs::read(file, buffer, 1, fileSize); VirtFs::close(file); @@ -185,8 +187,7 @@ namespace VirtFs std::string loadTextFileString(const std::string &fileName) { int contentsLength; - char *fileContents = static_cast<char*>( - VirtFs::loadFile(fileName, contentsLength)); + char *fileContents = VirtFs::loadFile(fileName, contentsLength); if (!fileContents) { @@ -194,7 +195,7 @@ namespace VirtFs return std::string(); } const std::string str = std::string(fileContents, contentsLength); - free(fileContents); + delete [] fileContents; return str; } @@ -202,8 +203,7 @@ namespace VirtFs StringVect &lines) { int contentsLength; - char *fileContents = static_cast<char*>( - VirtFs::loadFile(fileName, contentsLength)); + char *fileContents = VirtFs::loadFile(fileName, contentsLength); if (!fileContents) { @@ -217,7 +217,7 @@ namespace VirtFs while (getline(iss, line)) lines.push_back(line); - free(fileContents); + delete [] fileContents; return true; } } // namespace VirtFs diff --git a/src/fs/virtfs/virtfstools.h b/src/fs/virtfs/virtfstools.h index 4f2a77f4c..c9ff1d290 100644 --- a/src/fs/virtfs/virtfstools.h +++ b/src/fs/virtfs/virtfstools.h @@ -29,7 +29,7 @@ namespace VirtFs { - void *loadFile(const std::string &restrict fileName, + char *loadFile(const std::string &restrict fileName, int &restrict fileSize); void searchAndAddArchives(const std::string &restrict path, const std::string &restrict ext, |