Merge pull request #55 from bparker06/nul

allocate enough space for NUL, and don't try to open an empty file string
This commit is contained in:
Twinaphex
2016-12-31 08:02:05 +01:00
committed by GitHub
3 changed files with 15 additions and 5 deletions

View File

@@ -172,7 +172,10 @@ void FCEUD_VideoChanged (void)
FILE *FCEUD_UTF8fopen(const char *n, const char *m)
{
return fopen(n, m);
if (n)
return fopen(n, m);
else
return NULL;
}
#define MAX_PATH 1024

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);
}

View File

@@ -324,8 +324,14 @@ void FCEUSS_CheckStates(void)
for (ssel = 0; ssel < 10; ssel++)
{
st = fopen(fn = FCEU_MakeFName(FCEUMKF_STATE, ssel, 0), "rb");
free(fn);
fn = FCEU_MakeFName(FCEUMKF_STATE, ssel, 0);
if (fn)
{
st = fopen(fn, "rb");
free(fn);
}
if (st)
{
SaveStateStatus[ssel] = 1;