From ecb5899bcf9606698b3534edb435dcb2240be4c5 Mon Sep 17 00:00:00 2001 From: lieff Date: Wed, 19 Oct 2016 14:04:44 +0300 Subject: [PATCH] handle file IO error --- src/fontstash.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fontstash.h b/src/fontstash.h index 35dfb0f..d5b8aa5 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -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);