Merge pull request #329 from lieff/master

handle file IO error
This commit is contained in:
Mikko Mononen 2016-10-19 15:21:52 +03:00 committed by GitHub
commit 2ed5c0e010

View File

@ -873,7 +873,7 @@ error:
int fonsAddFont(FONScontext* stash, const char* name, const char* path)
{
FILE* fp = 0;
int dataSize = 0;
int dataSize = 0, readed;
unsigned char* data = NULL;
// Read in the font data.
@ -884,9 +884,10 @@ int fonsAddFont(FONScontext* stash, const char* name, const char* path)
fseek(fp,0,SEEK_SET);
data = (unsigned char*)malloc(dataSize);
if (data == NULL) goto error;
fread(data, 1, dataSize, fp);
readed = fread(data, 1, dataSize, fp);
fclose(fp);
fp = 0;
if (readed != dataSize) goto error;
return fonsAddFontMem(stash, name, data, dataSize, 1);