summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-12-26 02:28:59 +0100
committerHaru <haru@dotalux.com>2016-05-08 19:53:57 +0200
commit2349b2a1528fe5dc41d930f8dd332df5ba521eb6 (patch)
tree3656a91a896f0ef090606b2b4c9184ad73153a3f /src/common
parent58a7bf46508b7f186704e7efb39576e09f0ab866 (diff)
downloadhercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.tar.gz
hercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.tar.bz2
hercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.tar.xz
hercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.zip
Fixed various issues pointed out by cppcheck
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/grfio.c2
-rw-r--r--src/common/memmgr.c6
-rw-r--r--src/common/showmsg.c13
-rw-r--r--src/common/sql.c2
4 files changed, 10 insertions, 13 deletions
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 678875c91..c6e47d357 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -410,12 +410,12 @@ void *grfio_reads(const char *fname, int *size)
// LocalFileCheck
char lfname[256];
FILE *in;
- unsigned char *buf = NULL;
grfio_localpath_create(lfname, sizeof(lfname), (entry && entry->fnd) ? entry->fnd : fname);
in = fopen(lfname, "rb");
if (in != NULL) {
int declen;
+ unsigned char *buf = NULL;
fseek(in,0,SEEK_END);
declen = (int)ftell(in);
if (declen == -1) {
diff --git a/src/common/memmgr.c b/src/common/memmgr.c
index 15e55fbeb..dfea24465 100644
--- a/src/common/memmgr.c
+++ b/src/common/memmgr.c
@@ -154,8 +154,8 @@ void* aReallocz_(void *p, size_t size, const char *file, int line, const char *f
#ifdef USE_MEMMGR
ret = REALLOC(p, size, file, line, func);
#else
- size_t newSize;
- if (p) {
+ if (p != NULL) {
+ size_t newSize;
size_t oldSize = BUFFER_SIZE(p);
ret = REALLOC(p, size, file, line, func);
newSize = BUFFER_SIZE(ret);
@@ -167,7 +167,7 @@ void* aReallocz_(void *p, size_t size, const char *file, int line, const char *f
memset(ret, 0, BUFFER_SIZE(ret));
}
#endif
- if (ret == NULL){
+ if (ret == NULL) {
ShowFatalError("%s:%d: in func %s: aRealloc error out of memory!\n",file,line,func);
exit(EXIT_FAILURE);
}
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 1c1d4ca8b..8ed8efc1d 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -244,13 +244,13 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr)
continue;
} else if (*q == ';') {
// delimiter
- if (numpoint < sizeof(numbers)/sizeof(*numbers)) {
+ if (numpoint < ARRAYLENGTH(numbers)) {
// go to next array position
numpoint++;
} else {
// array is full, so we 'forget' the first value
- memmove(numbers,numbers+1,sizeof(numbers)/sizeof(*numbers)-1);
- numbers[sizeof(numbers)/sizeof(*numbers)-1]=0;
+ memmove(numbers, numbers+1, ARRAYLENGTH(numbers)-1);
+ numbers[ARRAYLENGTH(numbers)-1]=0;
}
++q;
// and next number
@@ -605,9 +605,6 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
{
va_list apcopy;
char prefix[100];
-#if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN)
- FILE *fp;
-#endif
if (!string || *string == '\0') {
ShowError("Empty string passed to vShowMessage_().\n");
@@ -702,8 +699,8 @@ int vShowMessage_(enum msg_type flag, const char *string, va_list ap)
}
#if defined(DEBUGLOGMAP) || defined(DEBUGLOGCHAR) || defined(DEBUGLOGLOGIN)
- if(strlen(DEBUGLOGPATH) > 0) {
- fp=fopen(DEBUGLOGPATH,"a");
+ if (strlen(DEBUGLOGPATH) > 0) {
+ FILE *fp = fopen(DEBUGLOGPATH,"a");
if (fp == NULL) {
FPRINTF(STDERR, CL_RED"[ERROR]"CL_RESET": Could not open '"CL_WHITE"%s"CL_RESET"', access denied.\n", DEBUGLOGPATH);
FFLUSH(STDERR);
diff --git a/src/common/sql.c b/src/common/sql.c
index 1eae1b29b..ef8cde536 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -880,10 +880,10 @@ void SqlStmt_Free(struct SqlStmt *self)
}
/* receives mysql error codes during runtime (not on first-time-connects) */
void hercules_mysql_error_handler(unsigned int ecode) {
- static unsigned int retry = 1;
switch( ecode ) {
case 2003:/* Can't connect to MySQL (this error only happens here when failing to reconnect) */
if( mysql_reconnect_type == 1 ) {
+ static unsigned int retry = 1;
if( ++retry > mysql_reconnect_count ) {
ShowFatalError("MySQL has been unreachable for too long, %u reconnects were attempted. Shutting Down\n", retry);
exit(EXIT_FAILURE);