summaryrefslogtreecommitdiff
path: root/src/common/grfio.c
diff options
context:
space:
mode:
authorMadCamel <madcamel@gmail.com>2010-04-04 16:15:43 -0400
committerMadCamel <madcamel@gmail.com>2010-04-04 16:15:43 -0400
commitb683a1ba9ba9e46bab0d8f94e38ef56669f8530a (patch)
treec90685468d3a67f4f2dc98d72b1d23d0745ad693 /src/common/grfio.c
parent3db7c2cd1c4fb0d8888416e9b5733abab574ebe9 (diff)
downloadtmwa-b683a1ba9ba9e46bab0d8f94e38ef56669f8530a.tar.gz
tmwa-b683a1ba9ba9e46bab0d8f94e38ef56669f8530a.tar.bz2
tmwa-b683a1ba9ba9e46bab0d8f94e38ef56669f8530a.tar.xz
tmwa-b683a1ba9ba9e46bab0d8f94e38ef56669f8530a.zip
Fixed some bad code that was generating compiler warnings
Diffstat (limited to 'src/common/grfio.c')
-rw-r--r--src/common/grfio.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 4795d5b..b460dc6 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -618,7 +618,8 @@ void *grfio_reads (char *fname, int *size)
printf ("file read memory allocate error : declen\n");
goto errret;
}
- fread (buf2, 1, lentry.declen, in);
+ if (!fread (buf2, 1, lentry.declen, in))
+ goto errret;
fclose_ (in);
in = NULL;
strncpy (lentry.fn, fname, sizeof (lentry.fn) - 1);
@@ -658,7 +659,8 @@ void *grfio_reads (char *fname, int *size)
return NULL;
}
fseek (in, entry->srcpos, 0);
- fread (buf, 1, entry->srclen_aligned, in);
+ if (!fread (buf, 1, entry->srclen_aligned, in))
+ goto errret;
fclose_ (in);
buf2 = calloc (entry->declen + 1024, 1);
if (buf2 == NULL)
@@ -751,7 +753,9 @@ static int grfio_entryread (char *gfname, int gentry)
fseek (fp, 0, 2); // SEEK_END
grf_size = ftell (fp);
fseek (fp, 0, 0); // SEEK_SET
- fread (grf_header, 1, 0x2e, fp);
+ if (!fread (grf_header, 1, 0x2e, fp))
+ return 2;
+
if (strcmp (grf_header, "Master of Magic")
|| fseek (fp, getlong (grf_header + 0x1e), 1))
{ // SEEK_CUR
@@ -772,7 +776,8 @@ static int grfio_entryread (char *gfname, int gentry)
printf ("out of memory : grf_filelist\n");
return 3; // 3:memory alloc error
}
- fread (grf_filelist, 1, list_size, fp);
+ if (!fread (grf_filelist, 1, list_size, fp))
+ return 2;
fclose_ (fp);
entrys =
@@ -852,7 +857,9 @@ static int grfio_entryread (char *gfname, int gentry)
unsigned char *rBuf;
uLongf rSize, eSize;
- fread (eheader, 1, 8, fp);
+ if (!fread (eheader, 1, 8, fp))
+ return 4;
+
rSize = getlong (eheader); // Read Size
eSize = getlong (eheader + 4); // Extend Size
@@ -878,7 +885,10 @@ static int grfio_entryread (char *gfname, int gentry)
printf ("out of memory : grf extract entry table buffer\n");
return 3;
}
- fread (rBuf, 1, rSize, fp);
+
+ if (!fread (rBuf, 1, rSize, fp))
+ return 4;
+
fclose_ (fp);
decode_zip (grf_filelist, &eSize, rBuf, rSize); // Decode function
list_size = eSize;