shithub: choc

Download patch

ref: 8b8b46cd3690fd3413b7b7b5902ff939a9843743
parent: de175686e6831c7aeff6cad874de873dbc1d15a6
author: Turo Lamminen <turotl@gmail.com>
date: Sat Feb 3 10:15:43 EST 2018

misc: Always add terminating '\0' in M_ReadFile

--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -217,7 +217,7 @@
 
     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);
 	
@@ -224,6 +224,7 @@
     if (count < length)
 	I_Error ("Couldn't read file %s", name);
 		
+    buf[length] = '\0';
     *buffer = buf;
     return length;
 }