allocate enough space for NUL, and do not try to open an empty file string

This commit is contained in:
Brad Parker
2016-12-31 01:56:52 -05:00
parent 309c8db34d
commit 821ca02474
3 changed files with 15 additions and 5 deletions

View File

@@ -91,8 +91,9 @@ char *FCEU_MakeFName(int type, int id1, char *cd1)
break;
}
ret = (char*)malloc(strlen(tmp) * sizeof(char));
strncpy(ret, tmp, strlen(tmp));
ret = (char*)malloc(strlen(tmp) * sizeof(char) + 1);
strncpy(ret, tmp, strlen(tmp) + 1);
return(ret);
}