Commit 23b64754 authored by Ed Avis's avatar Ed Avis Committed by Albert Astals Cid

Check for fseek return values

parent b33bb282
......@@ -14,6 +14,7 @@
#include <stdio.h>
#include "goo/gmem.h"
#include "Error.h"
#include "FoFiBase.h"
//------------------------------------------------------------------------
......@@ -38,11 +39,20 @@ char *FoFiBase::readFile(char *fileName, int *fileLen) {
int n;
if (!(f = fopen(fileName, "rb"))) {
error(-1, "Cannot open '%s'", fileName);
return NULL;
}
if (fseek(f, 0, SEEK_END) != 0) {
error(-1, "Cannot seek to end of '%s'", fileName);
fclose(f);
return NULL;
}
fseek(f, 0, SEEK_END);
n = (int)ftell(f);
fseek(f, 0, SEEK_SET);
if (fseek(f, 0, SEEK_SET) != 0) {
error(-1, "Cannot seek to start of '%s'", fileName);
fclose(f);
return NULL;
}
buf = (char *)gmalloc(n);
if ((int)fread(buf, 1, n, f) != n) {
gfree(buf);
......
......@@ -408,9 +408,17 @@ char *GfxFont::readExtFontFile(int *len) {
error(-1, "External font file '%s' vanished", extFontFile->getCString());
return NULL;
}
fseek(f, 0, SEEK_END);
if (fseek(f, 0, SEEK_END) != 0) {
error(-1, "Cannot seek to end of '%s'", extFontFile->getCString());
fclose(f);
return NULL;
}
*len = (int)ftell(f);
fseek(f, 0, SEEK_SET);
if (fseek(f, 0, SEEK_SET) != 0) {
error(-1, "Cannot seek to start of '%s'", extFontFile->getCString());
fclose(f);
return NULL;
}
buf = (char *)gmalloc(*len);
if ((int)fread(buf, 1, *len, f) != *len) {
error(-1, "Error reading external font file '%s'",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment