foxygit / doom Log in
commit 8b8b46cd3690fd3413b7b7b5902ff939a9843743
Author:     Turo Lamminen <turotl@gmail.com>
AuthorDate: Sat Feb 3 15:15:43 2018 +0200
Commit:     Turo Lamminen <turotl@gmail.com>
CommitDate: Sat Mar 17 16:22:04 2018 +0200

    misc: Always add terminating '\0' in M_ReadFile
---
 src/m_misc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/m_misc.c b/src/m_misc.c
index 3469ba86..3edf783b 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -217,13 +217,14 @@ int M_ReadFile(const char *name, byte **buffer)

     length = M_FileLength(handle);

-    buf = Z_Malloc (length, PU_STATIC, NULL);
+    buf = Z_Malloc (length + 1, PU_STATIC, NULL);
     count = fread(buf, 1, length, handle);
     fclose (handle);

     if (count < length)
 	I_Error ("Couldn't read file %s", name);

+    buf[length] = '\0';
     *buffer = buf;
     return length;
 }