summaryrefslogtreecommitdiff
path: root/src/fileio.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-02-24 20:59:17 +0000
committersmatz <smatz@openttd.org>2009-02-24 20:59:17 +0000
commit34bfb3510567e66b6bb584ad7f8ec48ff2b5095e (patch)
tree50574d6b6befd846433d33e7a7a619e719b57d0a /src/fileio.cpp
parent471c770a08f159af22ce9d7dcdbbb0e675ca8bac (diff)
downloadopenttd-34bfb3510567e66b6bb584ad7f8ec48ff2b5095e.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.cpp11
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);