Don't overlap strncpy in WAD file load

This commit is contained in:
Sryder 2019-06-23 14:52:49 +01:00
parent bb9b1b3b1f
commit 5f339fc2a9

View file

@ -149,9 +149,15 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors)
{ {
FILE *handle; FILE *handle;
strncpy(filenamebuf, *filename, MAX_WADPATH); // Officially, strncpy should not have overlapping buffers, since W_VerifyNMUSlumps is called after this, and it
filenamebuf[MAX_WADPATH - 1] = '\0'; // changes filename to point at filenamebuf, it would technically be doing that. I doubt any issue will occur since
*filename = filenamebuf; // they point to the same location, but it's better to be safe and this is a simple change.
if (filenamebuf != *filename)
{
strncpy(filenamebuf, *filename, MAX_WADPATH);
filenamebuf[MAX_WADPATH - 1] = '\0';
*filename = filenamebuf;
}
// open wad file // open wad file
if ((handle = fopen(*filename, "rb")) == NULL) if ((handle = fopen(*filename, "rb")) == NULL)