summaryrefslogtreecommitdiff
path: root/src/common/grfio.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-12-10 19:48:55 +0100
committerHaru <haru@dotalux.com>2013-12-17 01:11:33 +0100
commit15a0f6dea6f4f3c5adc9a1bc9e7e8be81cc49c48 (patch)
treec5dd5b25003f8c21381c7a2e1f010dba71e40b90 /src/common/grfio.c
parenta23d072a66d2569ba13921522be3c82ae9aad576 (diff)
downloadhercules-15a0f6dea6f4f3c5adc9a1bc9e7e8be81cc49c48.tar.gz
hercules-15a0f6dea6f4f3c5adc9a1bc9e7e8be81cc49c48.tar.bz2
hercules-15a0f6dea6f4f3c5adc9a1bc9e7e8be81cc49c48.tar.xz
hercules-15a0f6dea6f4f3c5adc9a1bc9e7e8be81cc49c48.zip
Fixed several compiler warnings
- Warnings detected thanks to Xcode's compiler settings (more strict by default) and clang, warnings mostly but not only related to data sizes on 64 bit systems, that were silenced until now by very lax compiler settings. - This also decreases by a great deal the amount of warnings produced by MSVC in x64 mode (for the adventurous ones who tried that) - Also fixed (or silenced in case of false positives) the potential issues pointed out by the (awesome) clang static analyzer. - Patch co-produced with Ind, I'm merging and committing in his place! Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/grfio.c')
-rw-r--r--src/common/grfio.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 77b976926..57e8a5187 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -8,6 +8,7 @@
#include "../common/showmsg.h"
#include "../common/strlib.h"
#include "../common/utils.h"
+#include "../common/nullpo.h"
#include "grfio.h"
#include <stdio.h>
@@ -305,17 +306,21 @@ static FILELIST* filelist_find(const char* fname)
// returns the original file name
char* grfio_find_file(const char* fname)
{
- FILELIST *filelist = filelist_find(fname);
- if (!filelist) return NULL;
- return (!filelist->fnd ? filelist->fn : filelist->fnd);
+ FILELIST *flist = filelist_find(fname);
+ if (!flist) return NULL;
+ return (!flist->fnd ? flist->fn : flist->fnd);
}
// adds a FILELIST entry into the list of loaded files
-static FILELIST* filelist_add(FILELIST* entry)
-{
+static FILELIST* filelist_add(FILELIST* entry) {
int hash;
+ nullpo_ret(entry);
+#ifdef __clang_analyzer__
+ // Make clang's static analyzer shut up about a possible NULL pointer in &filelist[filelist_entrys]
+ nullpo_ret(&filelist[filelist_entrys]);
+#endif // __clang_analyzer__
- #define FILELIST_ADDS 1024 // number increment of file lists `
+#define FILELIST_ADDS 1024 // number increment of file lists `
if (filelist_entrys >= filelist_maxentry) {
filelist = (FILELIST *)aRealloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST));
@@ -323,7 +328,9 @@ static FILELIST* filelist_add(FILELIST* entry)
filelist_maxentry += FILELIST_ADDS;
}
- memcpy (&filelist[filelist_entrys], entry, sizeof(FILELIST));
+#undef FILELIST_ADDS
+
+ memcpy(&filelist[filelist_entrys], entry, sizeof(FILELIST));
hash = filehash(entry->fn);
filelist[filelist_entrys].next = filelist_hash[hash];
@@ -405,7 +412,7 @@ void* grfio_reads(const char* fname, int* size)
if( in != NULL ) {
int declen;
fseek(in,0,SEEK_END);
- declen = ftell(in);
+ declen = (int)ftell(in);
fseek(in,0,SEEK_SET);
buf2 = (unsigned char *)aMalloc(declen+1); // +1 for resnametable zero-termination
if(fread(buf2, 1, declen, in) != (size_t)declen) ShowError("An error occured in fread grfio_reads, fname=%s \n",fname);