diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 69b0cf75..f0fa1ce4 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -123,7 +123,8 @@ char *FILESYSTEM_getUserLevelDirectory() return levelDir; } -void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem, size_t *len) +void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem, + size_t *len, bool addnull) { PHYSFS_File *handle = PHYSFS_openRead(name); if (handle == NULL) @@ -135,7 +136,15 @@ void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem, size_t * { *len = length; } - *mem = (unsigned char*) malloc(length); + if (addnull) + { + *mem = (unsigned char *) malloc(length + 1); + mem[length] = 0; + } + else + { + *mem = (unsigned char*) malloc(length); + } PHYSFS_readBytes(handle, *mem, length); PHYSFS_close(handle); } @@ -165,7 +174,7 @@ bool FILESYSTEM_loadTiXmlDocument(const char *name, TiXmlDocument *doc) { /* TiXmlDocument.SaveFile doesn't account for Unicode paths, PHYSFS does */ unsigned char *mem = NULL; - FILESYSTEM_loadFileToMemory(name, &mem, NULL); + FILESYSTEM_loadFileToMemory(name, &mem, NULL, true); if (mem == NULL) { return false; diff --git a/desktop_version/src/FileSystemUtils.h b/desktop_version/src/FileSystemUtils.h index 71274daf..d3c551e2 100644 --- a/desktop_version/src/FileSystemUtils.h +++ b/desktop_version/src/FileSystemUtils.h @@ -12,7 +12,8 @@ void FILESYSTEM_deinit(); char *FILESYSTEM_getUserSaveDirectory(); char *FILESYSTEM_getUserLevelDirectory(); -void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem, size_t *len); +void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem, + size_t *len, bool addnull = false); void FILESYSTEM_freeMemory(unsigned char **mem); bool FILESYSTEM_saveTiXmlDocument(const char *name, TiXmlDocument *doc); bool FILESYSTEM_loadTiXmlDocument(const char *name, TiXmlDocument *doc);