Fix potential NULL pointer dereferences

This commit is contained in:
Stanislav Gromov 2020-12-06 20:41:52 +07:00
parent 55d89321a0
commit 98c521793e
2 changed files with 7 additions and 1 deletions

View File

@ -32,6 +32,11 @@ memfile_t *memfile_creat(const char *name, size_t init)
mf.offs = 0;
pmf = (memfile_t *)malloc(sizeof(memfile_t));
if (!pmf)
{
free(mf.base);
return NULL;
}
memcpy(pmf, &mf, sizeof(memfile_t));
pmf->name = strdup(name);

View File

@ -44,7 +44,8 @@
SC_FUNC char* duplicatestring(const char* sourcestring)
{
char* result=(char*)malloc(strlen(sourcestring)+1);
strcpy(result,sourcestring);
if (result!=NULL)
strcpy(result,sourcestring);
return result;
}