diff options
author | smatz <smatz@openttd.org> | 2009-02-24 20:59:17 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-02-24 20:59:17 +0000 |
commit | d73c1fa7bfed01a187e14c4d86cde70e7121c51b (patch) | |
tree | 50574d6b6befd846433d33e7a7a619e719b57d0a /src/fileio.cpp | |
parent | 8beca127ddf8f97b76c4bd3491ead1f6954b115d (diff) | |
download | openttd-d73c1fa7bfed01a187e14c4d86cde70e7121c51b.tar.xz |
(svn r15568) -Cleanup: *allocT/AllocaM doesn't return NULL when allocating fails
Diffstat (limited to 'src/fileio.cpp')
-rw-r--r-- | src/fileio.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp index 19f4f4de1..59620df5c 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -991,20 +991,17 @@ void SanitizeFilename(char *filename) void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize) { - FILE *in; - byte *mem; - size_t len; - - in = fopen(filename, "rb"); + FILE *in = fopen(filename, "rb"); if (in == NULL) return NULL; fseek(in, 0, SEEK_END); - len = ftell(in); + size_t len = ftell(in); fseek(in, 0, SEEK_SET); - if (len > maxsize || (mem = MallocT<byte>(len + 1)) == NULL) { + if (len > maxsize) { fclose(in); return NULL; } + byte *mem = MallocT<byte>(len + 1); mem[len] = 0; if (fread(mem, len, 1, in) != 1) { fclose(in); |