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/virtfs/virtfstools.cpp | |
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/virtfs/virtfstools.cpp')
-rw-r--r-- | src/fs/virtfs/virtfstools.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
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 |