summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-11-19 02:20:07 -0200
committershennetsind <ind@henn.et>2013-11-19 02:20:07 -0200
commit242bc9fc39c90364dcf5f1a73a6d759efeef0ffd (patch)
tree0ac9e1e42c5db47d46f5a2d9e9d665b20fb46f63 /src/common
parentd076f129c90ac9e3a96659488f702f81def1863a (diff)
parentcb85f27f1ee334982fc3f9dfc1ffe824a1f8905c (diff)
downloadhercules-242bc9fc39c90364dcf5f1a73a6d759efeef0ffd.tar.gz
hercules-242bc9fc39c90364dcf5f1a73a6d759efeef0ffd.tar.bz2
hercules-242bc9fc39c90364dcf5f1a73a6d759efeef0ffd.tar.xz
hercules-242bc9fc39c90364dcf5f1a73a6d759efeef0ffd.zip
Merge branch 'master' of https://github.com/HerculesWS/Hercules
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c1
-rw-r--r--src/common/HPM.h24
-rw-r--r--src/common/HPMi.h32
-rw-r--r--src/common/cbasetypes.h10
-rw-r--r--src/common/console.c4
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/db.c2
-rw-r--r--src/common/db.h12
-rw-r--r--src/common/ers.h10
-rw-r--r--src/common/grfio.h2
-rw-r--r--src/common/malloc.c64
-rw-r--r--src/common/malloc.h16
-rw-r--r--src/common/mapindex.h2
-rw-r--r--src/common/mempool.c10
-rw-r--r--src/common/mmo.h2
-rw-r--r--src/common/netbuffer.h10
-rw-r--r--src/common/network.c2
-rw-r--r--src/common/raconf.c29
-rw-r--r--src/common/showmsg.c111
-rw-r--r--src/common/socket.c26
-rw-r--r--src/common/socket.h21
-rw-r--r--src/common/spinlock.h4
-rw-r--r--src/common/sql.h14
-rw-r--r--src/common/strlib.h32
-rw-r--r--src/common/timer.h2
-rw-r--r--src/common/utils.h2
26 files changed, 211 insertions, 235 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 1f4d4d532..641ffe2e6 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -108,6 +108,7 @@ bool hplugin_populate(struct hplugin *plugin, const char *filename) {
return true;
}
+#undef HPM_POP
struct hplugin *hplugin_load(const char* filename) {
struct hplugin *plugin;
struct hplugin_info *info;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 9a6bda713..5466693ab 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -12,29 +12,29 @@
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
- #define plugin_open(x) LoadLibraryA(x)
- #define plugin_import(x,y,z) (z)GetProcAddress(x,y)
- #define plugin_close(x) FreeLibrary(x)
+ #define plugin_open(x) LoadLibraryA(x)
+ #define plugin_import(x,y,z) (z)GetProcAddress((x),(y))
+ #define plugin_close(x) FreeLibrary(x)
- #define DLL_EXT ".dll"
- #define DLL HINSTANCE
+ #define DLL_EXT ".dll"
+ #define DLL HINSTANCE
#else // ! WIN32
#include <dlfcn.h>
#ifdef RTLD_DEEPBIND // Certain linux ditributions require this, but it's not available everywhere
- #define plugin_open(x) dlopen(x,RTLD_NOW|RTLD_DEEPBIND)
+ #define plugin_open(x) dlopen((x),RTLD_NOW|RTLD_DEEPBIND)
#else // ! RTLD_DEEPBIND
- #define plugin_open(x) dlopen(x,RTLD_NOW)
+ #define plugin_open(x) dlopen((x),RTLD_NOW)
#endif // RTLD_DEEPBIND
- #define plugin_import(x,y,z) (z)dlsym(x,y)
- #define plugin_close(x) dlclose(x)
+ #define plugin_import(x,y,z) (z)dlsym((x),(y))
+ #define plugin_close(x) dlclose(x)
#ifdef CYGWIN
- #define DLL_EXT ".dll"
+ #define DLL_EXT ".dll"
#else
- #define DLL_EXT ".so"
+ #define DLL_EXT ".so"
#endif
- #define DLL void *
+ #define DLL void *
#include <string.h> // size_t
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index 940782dce..7637dc832 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -47,9 +47,9 @@ struct hplugin_info {
HPExport void *(*import_symbol) (char *name, unsigned int pID);
HPExport Sql *mysql_handle;
-#define GET_SYMBOL(n) import_symbol(n,HPMi->pid)
+#define GET_SYMBOL(n) import_symbol((n),HPMi->pid)
-#define SERVER_TYPE_ALL SERVER_TYPE_LOGIN|SERVER_TYPE_CHAR|SERVER_TYPE_MAP
+#define SERVER_TYPE_ALL (SERVER_TYPE_LOGIN|SERVER_TYPE_CHAR|SERVER_TYPE_MAP)
enum hp_event_types {
HPET_INIT,/* server starts */
@@ -83,27 +83,27 @@ enum HPluginDataTypes {
HPDT_NPCD,
};
-#define addHookPre(tname,hook) HPMi->AddHook(HOOK_TYPE_PRE,tname,hook,HPMi->pid)
-#define addHookPost(tname,hook) HPMi->AddHook(HOOK_TYPE_POST,tname,hook,HPMi->pid)
+#define addHookPre(tname,hook) (HPMi->AddHook(HOOK_TYPE_PRE,(tname),(hook),HPMi->pid))
+#define addHookPost(tname,hook) (HPMi->AddHook(HOOK_TYPE_POST,(tname),(hook),HPMi->pid))
/* need better names ;/ */
/* will not run the original function after pre-hook processing is complete (other hooks will run) */
-#define hookStop() HPMi->HookStop(__func__,HPMi->pid)
-#define hookStopped() HPMi->HookStopped()
+#define hookStop() (HPMi->HookStop(__func__,HPMi->pid))
+#define hookStopped() (HPMi->HookStopped())
-#define addArg(name,param,func,help) HPMi->addArg(HPMi->pid,name,param,func,help)
+#define addArg(name,param,func,help) (HPMi->addArg(HPMi->pid,(name),(param),(func),(help)))
/* HPData handy redirects */
/* session[] */
-#define addToSession(ptr,data,index,autofree) HPMi->addToHPData(HPDT_SESSION,HPMi->pid,ptr,data,index,autofree)
-#define getFromSession(ptr,index) HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,ptr,index)
-#define removeFromSession(ptr,index) HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,ptr,index)
+#define addToSession(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_SESSION,HPMi->pid,(ptr),(data),(index),(autofree)))
+#define getFromSession(ptr,index) (HPMi->getFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index)))
+#define removeFromSession(ptr,index) (HPMi->removeFromHPData(HPDT_SESSION,HPMi->pid,(ptr),(index)))
/* map_session_data */
-#define addToMSD(ptr,data,index,autofree) HPMi->addToHPData(HPDT_MSD,HPMi->pid,ptr,data,index,autofree)
-#define getFromMSD(ptr,index) HPMi->getFromHPData(HPDT_MSD,HPMi->pid,ptr,index)
-#define removeFromMSD(ptr,index) HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,ptr,index)
+#define addToMSD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_MSD,HPMi->pid,(ptr),(data),(index),(autofree)))
+#define getFromMSD(ptr,index) (HPMi->getFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index)))
+#define removeFromMSD(ptr,index) (HPMi->removeFromHPData(HPDT_MSD,HPMi->pid,(ptr),(index)))
/* npc_data */
-#define addToNPCD(ptr,data,index,autofree) HPMi->addToHPData(HPDT_NPCD,HPMi->pid,ptr,data,index,autofree)
-#define getFromNPCD(ptr,index) HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,ptr,index)
-#define removeFromNPCD(ptr,index) HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,ptr,index)
+#define addToNPCD(ptr,data,index,autofree) (HPMi->addToHPData(HPDT_NPCD,HPMi->pid,(ptr),(data),(index),(autofree)))
+#define getFromNPCD(ptr,index) (HPMi->getFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index)))
+#define removeFromNPCD(ptr,index) (HPMi->removeFromHPData(HPDT_NPCD,HPMi->pid,(ptr),(index)))
/* Hercules Plugin Mananger Include Interface */
HPExport struct HPMi_interface {
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index d2a0a5dd9..6de2ace01 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -293,7 +293,9 @@ typedef char bool;
// if using macros then something that is type independent
//#define swap(a,b) ((a == b) || ((a ^= b), (b ^= a), (a ^= b)))
// Avoid "value computed is not used" warning and generates the same assembly code
-#define swap(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
+//#define swap(a,b) if (a != b) ((a ^= b), (b ^= a), (a ^= b))
+// but is vulnerable to 'if (foo) swap(bar, baz); else quux();', causing the else to nest incorrectly.
+#define swap(a,b) do { if ((a) != (b)) { (a) ^= (b); (b) ^= (a); (a) ^= (b); } } while(0)
#if 0 //to be activated soon, more tests needed on how VS works with the macro above
#ifdef WIN32
#undef swap
@@ -313,7 +315,7 @@ typedef char bool;
#endif
#endif
-#define swap_ptr(a,b) if ((a) != (b)) ((a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)), (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)))
+#define swap_ptr(a,b) do { if ((a) != (b)) (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); (b) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); (a) = (void*)((intptr_t)(a) ^ (intptr_t)(b)); } while(0)
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
@@ -429,8 +431,8 @@ void SET_FUNCPOINTER(T1& var, T2 p)
var = tmp.out;
}
#else
-#define SET_POINTER(var,p) (var) = (p)
-#define SET_FUNCPOINTER(var,p) (var) = (p)
+#define SET_POINTER(var,p) ((var) = (p))
+#define SET_FUNCPOINTER(var,p) ((var) = (p))
#endif
diff --git a/src/common/console.c b/src/common/console.c
index cb8ed5917..94824dc25 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -175,6 +175,10 @@ void console_load_defaults(void) {
}
}
}
+#undef CP_DEF_C
+#undef CP_DEF_C2
+#undef CP_DEF_S
+#undef CP_DEF
void console_parse_create(char *name, CParseFunc func) {
unsigned int i;
char *tok;
diff --git a/src/common/core.c b/src/common/core.c
index a414a5d0b..dd839b372 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -53,7 +53,7 @@ char *SERVER_NAME = NULL;
#endif
#ifndef POSIX
-#define compat_signal(signo, func) signal(signo, func)
+#define compat_signal(signo, func) signal((signo), (func))
#else
sigfunc *compat_signal(int signo, sigfunc *func) {
struct sigaction sact, oact;
diff --git a/src/common/db.c b/src/common/db.c
index b3a58e0a4..c3ca7e0a4 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -315,7 +315,7 @@ static struct db_stats {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
};
-#define DB_COUNTSTAT(token) if (stats. ## token != UINT32_MAX) ++stats. ## token
+#define DB_COUNTSTAT(token) do { if (stats. ## token != UINT32_MAX) ++stats. ## token ; } while(0)
#else /* !defined(DB_ENABLE_STATS) */
#define DB_COUNTSTAT(token)
#endif /* !defined(DB_ENABLE_STATS) */
diff --git a/src/common/db.h b/src/common/db.h
index dffd2356d..b9d6af382 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -659,14 +659,14 @@ struct DBMap {
#define stridb_alloc(opt,maxlen) DB->alloc(__FILE__,__func__,__LINE__,DB_ISTRING,(opt),(maxlen))
#define db_destroy(db) ( (db)->destroy((db),NULL) )
// Other macros
-#define db_clear(db) ( (db)->clear(db,NULL) )
+#define db_clear(db) ( (db)->clear((db),NULL) )
#define db_size(db) ( (db)->size(db) )
#define db_iterator(db) ( (db)->iterator(db) )
-#define dbi_first(dbi) ( DB->data2ptr((dbi)->first(dbi,NULL)) )
-#define dbi_last(dbi) ( DB->data2ptr((dbi)->last(dbi,NULL)) )
-#define dbi_next(dbi) ( DB->data2ptr((dbi)->next(dbi,NULL)) )
-#define dbi_prev(dbi) ( DB->data2ptr((dbi)->prev(dbi,NULL)) )
-#define dbi_remove(dbi) ( (dbi)->remove(dbi,NULL) )
+#define dbi_first(dbi) ( DB->data2ptr((dbi)->first((dbi),NULL)) )
+#define dbi_last(dbi) ( DB->data2ptr((dbi)->last((dbi),NULL)) )
+#define dbi_next(dbi) ( DB->data2ptr((dbi)->next((dbi),NULL)) )
+#define dbi_prev(dbi) ( DB->data2ptr((dbi)->prev((dbi),NULL)) )
+#define dbi_remove(dbi) ( (dbi)->remove((dbi),NULL) )
#define dbi_exists(dbi) ( (dbi)->exists(dbi) )
#define dbi_destroy(dbi) ( (dbi)->destroy(dbi) )
diff --git a/src/common/ers.h b/src/common/ers.h
index 51701d778..4ff2a6230 100644
--- a/src/common/ers.h
+++ b/src/common/ers.h
@@ -137,11 +137,11 @@ typedef struct eri {
#else /* not DISABLE_ERS */
// These defines should be used to allow the code to keep working whenever
// the system is disabled
-# define ers_alloc(obj,type) (type *)(obj)->alloc(obj)
-# define ers_free(obj,entry) (obj)->free((obj),(entry))
-# define ers_entry_size(obj) (obj)->entry_size(obj)
-# define ers_destroy(obj) (obj)->destroy(obj)
-# define ers_chunk_size(obj,size) (obj)->chunk_size(obj,size)
+# define ers_alloc(obj,type) ((type *)(obj)->alloc(obj))
+# define ers_free(obj,entry) ((obj)->free((obj),(entry)))
+# define ers_entry_size(obj) ((obj)->entry_size(obj))
+# define ers_destroy(obj) ((obj)->destroy(obj))
+# define ers_chunk_size(obj,size) ((obj)->chunk_size((obj),(size)))
/**
* Get a new instance of the manager that handles the specified entry size.
diff --git a/src/common/grfio.h b/src/common/grfio.h
index c5a56a14e..a88b20393 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -8,7 +8,7 @@ void grfio_init(const char* fname);
void grfio_final(void);
void* grfio_reads(const char* fname, int* size);
char* grfio_find_file(const char* fname);
-#define grfio_read(fn) grfio_reads(fn, NULL)
+#define grfio_read(fn) grfio_reads((fn), NULL)
unsigned long grfio_crc32(const unsigned char *buf, unsigned int len);
int decode_zip(void* dest, unsigned long* destLen, const void* source, unsigned long sourceLen);
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 4d2c93b77..1cb7836ab 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -19,28 +19,28 @@ struct malloc_interface iMalloc_s;
# include <string.h>
# include "memwatch.h"
-# define MALLOC(n,file,line,func) mwMalloc((n),(file),(line))
-# define CALLOC(m,n,file,line,func) mwCalloc((m),(n),(file),(line))
-# define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line))
-# define STRDUP(p,file,line,func) mwStrdup((p),(file),(line))
-# define FREE(p,file,line,func) mwFree((p),(file),(line))
-# define MEMORY_USAGE() 0
-# define MEMORY_VERIFY(ptr) mwIsSafeAddr(ptr, 1)
-# define MEMORY_CHECK() CHECK()
+# define MALLOC(n,file,line,func) mwMalloc((n),(file),(line))
+# define CALLOC(m,n,file,line,func) mwCalloc((m),(n),(file),(line))
+# define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line))
+# define STRDUP(p,file,line,func) mwStrdup((p),(file),(line))
+# define FREE(p,file,line,func) mwFree((p),(file),(line))
+# define MEMORY_USAGE() (size_t)0
+# define MEMORY_VERIFY(ptr) mwIsSafeAddr((ptr), 1)
+# define MEMORY_CHECK() CHECK()
#elif defined(DMALLOC)
# include <string.h>
# include <stdlib.h>
# include "dmalloc.h"
-# define MALLOC(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0)
-# define CALLOC(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0)
-# define REALLOC(p,n,file,line,func) dmalloc_realloc((file),(line),(p),(n),DMALLOC_FUNC_REALLOC,0)
-# define STRDUP(p,file,line,func) strdup(p)
-# define FREE(p,file,line,func) free(p)
-# define MEMORY_USAGE() dmalloc_memory_allocated()
-# define MEMORY_VERIFY(ptr) (dmalloc_verify(ptr) == DMALLOC_VERIFY_NOERROR)
-# define MEMORY_CHECK() dmalloc_log_stats(); dmalloc_log_unfreed()
+# define MALLOC(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0)
+# define CALLOC(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0)
+# define REALLOC(p,n,file,line,func) dmalloc_realloc((file),(line),(p),(n),DMALLOC_FUNC_REALLOC,0)
+# define STRDUP(p,file,line,func) strdup(p)
+# define FREE(p,file,line,func) free(p)
+# define MEMORY_USAGE() dmalloc_memory_allocated()
+# define MEMORY_VERIFY(ptr) (dmalloc_verify(ptr) == DMALLOC_VERIFY_NOERROR)
+# define MEMORY_CHECK() do { dmalloc_log_stats(); dmalloc_log_unfreed() } while(0)
#elif defined(GCOLLECT)
@@ -50,24 +50,26 @@ struct malloc_interface iMalloc_s;
# else
# define RETURN_ADDR
# endif
-# define MALLOC(n,file,line,func) GC_debug_malloc((n), RETURN_ADDR (file),(line))
-# define CALLOC(m,n,file,line,func) GC_debug_malloc((m)*(n), RETURN_ADDR (file),(line))
-# define REALLOC(p,n,file,line,func) GC_debug_realloc((p),(n), RETURN_ADDR (file),(line))
-# define STRDUP(p,file,line,func) GC_debug_strdup((p), RETURN_ADDR (file),(line))
-# define FREE(p,file,line,func) GC_debug_free(p)
-# define MEMORY_USAGE() GC_get_heap_size()
-# define MEMORY_VERIFY(ptr) (GC_base(ptr) != NULL)
-# define MEMORY_CHECK() GC_gcollect()
+# define MALLOC(n,file,line,func) GC_debug_malloc((n), RETURN_ADDR (file),(line))
+# define CALLOC(m,n,file,line,func) GC_debug_malloc((m)*(n), RETURN_ADDR (file),(line))
+# define REALLOC(p,n,file,line,func) GC_debug_realloc((p),(n), RETURN_ADDR (file),(line))
+# define STRDUP(p,file,line,func) GC_debug_strdup((p), RETURN_ADDR (file),(line))
+# define FREE(p,file,line,func) GC_debug_free(p)
+# define MEMORY_USAGE() GC_get_heap_size()
+# define MEMORY_VERIFY(ptr) (GC_base(ptr) != NULL)
+# define MEMORY_CHECK() GC_gcollect()
+
+# undef RETURN_ADDR
#else
-# define MALLOC(n,file,line,func) malloc(n)
-# define CALLOC(m,n,file,line,func) calloc((m),(n))
-# define REALLOC(p,n,file,line,func) realloc((p),(n))
-# define STRDUP(p,file,line,func) strdup(p)
-# define FREE(p,file,line,func) free(p)
-# define MEMORY_USAGE() 0
-# define MEMORY_VERIFY(ptr) true
+# define MALLOC(n,file,line,func) malloc(n)
+# define CALLOC(m,n,file,line,func) calloc((m),(n))
+# define REALLOC(p,n,file,line,func) realloc((p),(n))
+# define STRDUP(p,file,line,func) strdup(p)
+# define FREE(p,file,line,func) free(p)
+# define MEMORY_USAGE() (size_t)0
+# define MEMORY_VERIFY(ptr) true
# define MEMORY_CHECK()
#endif
diff --git a/src/common/malloc.h b/src/common/malloc.h
index bc8aa9a20..cd0ef238b 100644
--- a/src/common/malloc.h
+++ b/src/common/malloc.h
@@ -30,11 +30,11 @@
#undef LOG_MEMMGR
#endif
-# define aMalloc(n) iMalloc->malloc (n,ALC_MARK)
-# define aCalloc(m,n) iMalloc->calloc (m,n,ALC_MARK)
-# define aRealloc(p,n) iMalloc->realloc (p,n,ALC_MARK)
-# define aStrdup(p) iMalloc->astrdup (p,ALC_MARK)
-# define aFree(p) iMalloc->free (p,ALC_MARK)
+# define aMalloc(n) (iMalloc->malloc((n),ALC_MARK))
+# define aCalloc(m,n) (iMalloc->calloc((m),(n),ALC_MARK))
+# define aRealloc(p,n) (iMalloc->realloc((p),(n),ALC_MARK))
+# define aStrdup(p) (iMalloc->astrdup((p),ALC_MARK))
+# define aFree(p) (iMalloc->free((p),ALC_MARK))
/////////////// Buffer Creation /////////////////
// Full credit for this goes to Shinomori [Ajarn]
@@ -46,15 +46,15 @@
#else // others don't, so we emulate them
-#define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc (size, sizeof(type))
+#define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc((size), sizeof(type))
#define DELETE_BUFFER(name) aFree(name)
#endif
////////////// Others //////////////////////////
// should be merged with any of above later
-#define CREATE(result, type, number) (result) = (type *) aCalloc ((number), sizeof(type))
-#define RECREATE(result, type, number) (result) = (type *) aRealloc ((result), sizeof(type) * (number))
+#define CREATE(result, type, number) ((result) = (type *) aCalloc((number), sizeof(type)))
+#define RECREATE(result, type, number) ((result) = (type *) aRealloc((result), sizeof(type) * (number)))
////////////////////////////////////////////////
diff --git a/src/common/mapindex.h b/src/common/mapindex.h
index 646f73f18..cf5486808 100644
--- a/src/common/mapindex.h
+++ b/src/common/mapindex.h
@@ -60,7 +60,7 @@ bool mapindex_exists(int id);
const char* mapindex_getmapname(const char* string, char* output);
const char* mapindex_getmapname_ext(const char* string, char* output);
unsigned short mapindex_name2id(const char*);
-#define mapindex_id2name(n) mapindex_id2name_sub(n,__FILE__, __LINE__, __func__)
+#define mapindex_id2name(n) mapindex_id2name_sub((n),__FILE__, __LINE__, __func__)
const char* mapindex_id2name_sub(unsigned short,const char *file, int line, const char *func);
int mapindex_init(void);
void mapindex_final(void);
diff --git a/src/common/mempool.c b/src/common/mempool.c
index 5eccbf178..4559d8f2a 100644
--- a/src/common/mempool.c
+++ b/src/common/mempool.c
@@ -30,16 +30,16 @@
#include "../common/malloc.h"
#include "../common/mutex.h"
-#define ALIGN16 ra_align(16)
-#define ALIGN_TO(x, a) (x + ( a - ( x % a) ) )
-#define ALIGN_TO_16(x) ALIGN_TO(x, 16)
+#define ALIGN16 ra_align(16)
+#define ALIGN_TO(x, a) ((x) + ( (a) - ( (x) % (a)) ) )
+#define ALIGN_TO_16(x) ALIGN_TO((x), 16)
#undef MEMPOOL_DEBUG
#define MEMPOOLASSERT
-#define NODE_TO_DATA(x) ( ((char*)x) + sizeof(struct node) )
-#define DATA_TO_NODE(x) ( (struct node*)(((char*)x) - sizeof(struct node)) )
+#define NODE_TO_DATA(x) ( ((char*)(x)) + sizeof(struct node) )
+#define DATA_TO_NODE(x) ( (struct node*)(((char*)(x)) - sizeof(struct node)) )
struct ra_align(16) node{
void *next;
void *segment;
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 309203aa8..5816b467c 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -112,7 +112,7 @@
#define MAX_STORAGE 600
#define MAX_GUILD_STORAGE 600
#define MAX_PARTY 12
-#define MAX_GUILD 16+10*6 // Increased max guild members +6 per 1 extension levels [Lupus]
+#define MAX_GUILD (16+10*6) // Increased max guild members +6 per 1 extension levels [Lupus]
#define MAX_GUILDPOSITION 20 // Increased max guild positions to accomodate for all members [Valaris] (removed) [PoW]
#define MAX_GUILDEXPULSION 32
#define MAX_GUILDALLIANCE 16
diff --git a/src/common/netbuffer.h b/src/common/netbuffer.h
index 844241226..6ddecfdd9 100644
--- a/src/common/netbuffer.h
+++ b/src/common/netbuffer.h
@@ -73,11 +73,9 @@ void netbuffer_incref( netbuf buf );
// Some Useful macros
-#define NBUFP(netbuf,pos) (((uint8*)(netbuf->buf)) + (pos))
-#define NBUFB(netbuf,pos) (*(uint8*)((netbuf->buf) + (pos)))
-#define NBUFW(netbuf,pos) (*(uint16*)((netbuf->buf) + (pos)))
-#define NBUFL(netbuf,pos) (*(uint32*)((netbuf->buf) + (pos)))
-
-
+#define NBUFP(netbuf,pos) (((uint8*)((netbuf)->buf)) + (pos))
+#define NBUFB(netbuf,pos) (*(uint8*)(((netbuf)->buf) + (pos)))
+#define NBUFW(netbuf,pos) (*(uint16*)(((netbuf)->buf) + (pos)))
+#define NBUFL(netbuf,pos) (*(uint32*)(((netbuf)->buf) + (pos)))
#endif
diff --git a/src/common/network.c b/src/common/network.c
index 1f1621363..a40cbd602 100644
--- a/src/common/network.c
+++ b/src/common/network.c
@@ -50,7 +50,7 @@ SESSION g_Session[MAXCONN];
static bool onSend(int32 fd);
-#define _network_free_netbuf_async( buf ) add_timer( 0, _network_async_free_netbuf_proc, 0, (intptr_t) buf)
+#define _network_free_netbuf_async( buf ) add_timer( 0, _network_async_free_netbuf_proc, 0, (intptr_t)(buf))
static int _network_async_free_netbuf_proc(int tid, unsigned int tick, int id, intptr_t data){
// netbuf is in data
netbuffer_put( (netbuf)data );
diff --git a/src/common/raconf.c b/src/common/raconf.c
index f7d1284b7..abeed444b 100644
--- a/src/common/raconf.c
+++ b/src/common/raconf.c
@@ -382,21 +382,20 @@ static bool configParse(raconf inst, const char *fileName){
}//end: configParse()
-#define MAKEKEY(dest, section, key) { size_t section_len, key_len; \
- if(section == NULL || *section == '\0'){ \
- strncpy(dest, "<unnamed>", 9); \
- section_len = 9; \
- }else{ \
- section_len = strlen(section); \
- strncpy(dest, section, section_len); \
- } \
- \
- dest[section_len] = '.'; \
- \
- key_len = strlen(key); \
- strncpy(&dest[section_len+1], key, key_len); \
- dest[section_len + key_len + 1] = '\0'; \
- }
+#define MAKEKEY(dest, section, key) do { \
+ size_t section_len_, key_len_; \
+ if((section) == NULL || *(section) == '\0'){ \
+ strncpy((dest), "<unnamed>", 9); \
+ section_len_ = 9; \
+ } else { \
+ section_len_ = strlen(section); \
+ strncpy((dest), (section), section_len_); \
+ } \
+ (dest)[section_len_] = '.'; \
+ key_len_ = strlen(key); \
+ strncpy(&(dest)[section_len_+1], (key), key_len_); \
+ (dest)[section_len_ + key_len_ + 1] = '\0'; \
+} while(0)
raconf raconf_parse(const char *file_name){
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 9e0f63003..14342fe5e 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -16,33 +16,17 @@
#include "../../3rdparty/libconfig/libconfig.h"
#ifdef WIN32
- #include "../common/winapi.h"
-
- #ifdef DEBUGLOGMAP
- #define DEBUGLOGPATH "log\\map-server.log"
- #else
- #ifdef DEBUGLOGCHAR
- #define DEBUGLOGPATH "log\\char-server.log"
- #else
- #ifdef DEBUGLOGLOGIN
- #define DEBUGLOGPATH "log\\login-server.log"
- #endif
- #endif
- #endif
-#else
- #include <unistd.h>
-
- #ifdef DEBUGLOGMAP
- #define DEBUGLOGPATH "log/map-server.log"
- #else
- #ifdef DEBUGLOGCHAR
- #define DEBUGLOGPATH "log/char-server.log"
- #else
- #ifdef DEBUGLOGLOGIN
- #define DEBUGLOGPATH "log/login-server.log"
- #endif
- #endif
- #endif
+#include "../common/winapi.h"
+#else // not WIN32
+#include <unistd.h>
+#endif // WIN32
+
+#if defined(DEBUGLOGMAP)
+#define DEBUGLOGPATH "log"PATHSEP_STR"map-server.log"
+#elif defined(DEBUGLOGCHAR)
+#define DEBUGLOGPATH "log"PATHSEP_STR"char-server.log"
+#elif defined(DEBUGLOGLOGIN)
+#define DEBUGLOGPATH "log"PATHSEP_STR"login-server.log"
#endif
///////////////////////////////////////////////////////////////////////////////
@@ -61,41 +45,40 @@ int console_msg_log = 0;//[Ind] msg error logging
#define SBUF_SIZE 2054 // never put less that what's required for the debug message
-#define NEWBUF(buf) \
- struct { \
- char s_[SBUF_SIZE]; \
- StringBuf *d_; \
- char *v_; \
- int l_; \
- } buf ={"",NULL,NULL,0}; \
+#define NEWBUF(buf) \
+ struct { \
+ char s_[SBUF_SIZE]; \
+ StringBuf *d_; \
+ char *v_; \
+ int l_; \
+ } buf ={"",NULL,NULL,0}; \
//define NEWBUF
-#define BUFVPRINTF(buf,fmt,args) \
- buf.l_ = vsnprintf(buf.s_, SBUF_SIZE, fmt, args); \
- if( buf.l_ >= 0 && buf.l_ < SBUF_SIZE ) \
- {/* static buffer */ \
- buf.v_ = buf.s_; \
- } \
- else \
- {/* dynamic buffer */ \
- buf.d_ = StrBuf->Malloc(); \
- buf.l_ = StrBuf->Vprintf(buf.d_, fmt, args); \
- buf.v_ = StrBuf->Value(buf.d_); \
- ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", buf.l_+1);\
- } \
-//define BUFVPRINTF
-
-#define BUFVAL(buf) buf.v_
-#define BUFLEN(buf) buf.l_
-
-#define FREEBUF(buf) \
- if( buf.d_ ) \
- { \
- StrBuf->Free(buf.d_); \
- buf.d_ = NULL; \
- } \
- buf.v_ = NULL; \
-//define FREEBUF
+#define BUFVPRINTF(buf,fmt,args) do { \
+ (buf).l_ = vsnprintf((buf).s_, SBUF_SIZE, (fmt), args); \
+ if( (buf).l_ >= 0 && (buf).l_ < SBUF_SIZE ) \
+ {/* static buffer */ \
+ (buf).v_ = (buf).s_; \
+ } \
+ else \
+ {/* dynamic buffer */ \
+ (buf).d_ = StrBuf->Malloc(); \
+ (buf).l_ = StrBuf->Vprintf((buf).d_, (fmt), args); \
+ (buf).v_ = StrBuf->Value((buf).d_); \
+ ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", (buf).l_+1); \
+ } \
+} while(0) //define BUFVPRINTF
+
+#define BUFVAL(buf) ((buf).v_)
+#define BUFLEN(buf) ((buf).l_)
+
+#define FREEBUF(buf) do {\
+ if( (buf).d_ ) { \
+ StrBuf->Free((buf).d_); \
+ (buf).d_ = NULL; \
+ } \
+ (buf).v_ = NULL; \
+} while(0) //define FREEBUF
///////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
@@ -666,14 +649,6 @@ int FPRINTF(FILE *file, const char *fmt, ...)
#endif// not _WIN32
-
-
-
-
-
-
-
-
char timestamp_format[20] = ""; //For displaying Timestamps
int _vShowMessage(enum msg_type flag, const char *string, va_list ap)
diff --git a/src/common/socket.c b/src/common/socket.c
index 6e877d9be..2ae9d44b3 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -157,19 +157,19 @@ char* sErr(int code)
return sbuf;
}
-#define sBind(fd,name,namelen) bind(fd2sock(fd),name,namelen)
-#define sConnect(fd,name,namelen) connect(fd2sock(fd),name,namelen)
-#define sIoctl(fd,cmd,argp) ioctlsocket(fd2sock(fd),cmd,argp)
-#define sListen(fd,backlog) listen(fd2sock(fd),backlog)
-#define sRecv(fd,buf,len,flags) recv(fd2sock(fd),buf,len,flags)
-#define sSelect select
-#define sSend(fd,buf,len,flags) send(fd2sock(fd),buf,len,flags)
-#define sSetsockopt(fd,level,optname,optval,optlen) setsockopt(fd2sock(fd),level,optname,optval,optlen)
-#define sShutdown(fd,how) shutdown(fd2sock(fd),how)
-#define sFD_SET(fd,set) FD_SET(fd2sock(fd),set)
-#define sFD_CLR(fd,set) FD_CLR(fd2sock(fd),set)
-#define sFD_ISSET(fd,set) FD_ISSET(fd2sock(fd),set)
-#define sFD_ZERO FD_ZERO
+#define sBind(fd,name,namelen) bind(fd2sock(fd),(name),(namelen))
+#define sConnect(fd,name,namelen) connect(fd2sock(fd),(name),(namelen))
+#define sIoctl(fd,cmd,argp) ioctlsocket(fd2sock(fd),(cmd),(argp))
+#define sListen(fd,backlog) listen(fd2sock(fd),(backlog))
+#define sRecv(fd,buf,len,flags) recv(fd2sock(fd),(buf),(len),(flags))
+#define sSelect select
+#define sSend(fd,buf,len,flags) send(fd2sock(fd),(buf),(len),(flags))
+#define sSetsockopt(fd,level,optname,optval,optlen) setsockopt(fd2sock(fd),(level),(optname),(optval),(optlen))
+#define sShutdown(fd,how) shutdown(fd2sock(fd),(how))
+#define sFD_SET(fd,set) FD_SET(fd2sock(fd),(set))
+#define sFD_CLR(fd,set) FD_CLR(fd2sock(fd),(set))
+#define sFD_ISSET(fd,set) FD_ISSET(fd2sock(fd),(set))
+#define sFD_ZERO FD_ZERO
/////////////////////////////////////////////////////////////////////
#else
diff --git a/src/common/socket.h b/src/common/socket.h
index 923fa2515..02817f653 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -24,18 +24,18 @@ struct HPluginData;
// socket I/O macros
#define RFIFOHEAD(fd)
-#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo(fd, size); }while(0)
+#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo((fd), (size)); }while(0)
#define RFIFOP(fd,pos) (session[fd]->rdata + session[fd]->rdata_pos + (pos))
#define WFIFOP(fd,pos) (session[fd]->wdata + session[fd]->wdata_size + (pos))
-#define RFIFOB(fd,pos) (*(uint8*)RFIFOP(fd,pos))
-#define WFIFOB(fd,pos) (*(uint8*)WFIFOP(fd,pos))
-#define RFIFOW(fd,pos) (*(uint16*)RFIFOP(fd,pos))
-#define WFIFOW(fd,pos) (*(uint16*)WFIFOP(fd,pos))
-#define RFIFOL(fd,pos) (*(uint32*)RFIFOP(fd,pos))
-#define WFIFOL(fd,pos) (*(uint32*)WFIFOP(fd,pos))
-#define RFIFOQ(fd,pos) (*(uint64*)RFIFOP(fd,pos))
-#define WFIFOQ(fd,pos) (*(uint64*)WFIFOP(fd,pos))
+#define RFIFOB(fd,pos) (*(uint8*)RFIFOP((fd),(pos)))
+#define WFIFOB(fd,pos) (*(uint8*)WFIFOP((fd),(pos)))
+#define RFIFOW(fd,pos) (*(uint16*)RFIFOP((fd),(pos)))
+#define WFIFOW(fd,pos) (*(uint16*)WFIFOP((fd),(pos)))
+#define RFIFOL(fd,pos) (*(uint32*)RFIFOP((fd),(pos)))
+#define WFIFOL(fd,pos) (*(uint32*)WFIFOP((fd),(pos)))
+#define RFIFOQ(fd,pos) (*(uint64*)RFIFOP((fd),(pos)))
+#define WFIFOQ(fd,pos) (*(uint64*)WFIFOP((fd),(pos)))
#define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size)
#define WFIFOSPACE(fd) (session[fd]->max_wdata - session[fd]->wdata_size)
@@ -146,8 +146,9 @@ void set_defaultparse(ParseFunc defaultparse);
uint32 host2ip(const char* hostname);
const char* ip2str(uint32 ip, char ip_str[16]);
uint32 str2ip(const char* ip_str);
+// Note: purposely returns four comma-separated arguments
#define CONVIP(ip) ((ip)>>24)&0xFF,((ip)>>16)&0xFF,((ip)>>8)&0xFF,((ip)>>0)&0xFF
-#define MAKEIP(a,b,c,d) (uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) )
+#define MAKEIP(a,b,c,d) ((uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) ))
uint16 ntows(uint16 netshort);
int socket_getips(uint32* ips, int max);
diff --git a/src/common/spinlock.h b/src/common/spinlock.h
index 3419bfdd5..9b9e4ce94 100644
--- a/src/common/spinlock.h
+++ b/src/common/spinlock.h
@@ -52,8 +52,8 @@ static forceinline void FinalizeSpinLock(PSPIN_LOCK lck){
}
-#define getsynclock(l) { while(1){ if(InterlockedCompareExchange(l, 1, 0) == 0) break; rathread_yield(); } }
-#define dropsynclock(l) { InterlockedExchange(l, 0); }
+#define getsynclock(l) do { if(InterlockedCompareExchange((l), 1, 0) == 0) break; rathread_yield(); } while(/*always*/1)
+#define dropsynclock(l) do { InterlockedExchange((l), 0); } while(0)
static forceinline void EnterSpinLock(PSPIN_LOCK lck){
int tid = rathread_get_tid();
diff --git a/src/common/sql.h b/src/common/sql.h
index da00edf2d..1fb436853 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -11,7 +11,7 @@
// Return codes
-#define SQL_ERROR -1
+#define SQL_ERROR (-1)
#define SQL_SUCCESS 0
#define SQL_NO_DATA 100
@@ -277,7 +277,7 @@ void sql_defaults(void);
#if defined(SQL_REMOVE_SHOWDEBUG)
#define Sql_ShowDebug(self) (void)0
#else
-#define Sql_ShowDebug(self) SQL->ShowDebug_(self, __FILE__, __LINE__)
+#define Sql_ShowDebug(self) (SQL->ShowDebug_((self), __FILE__, __LINE__))
#endif
void Sql_HerculesUpdateCheck(Sql* self);
@@ -286,16 +286,10 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename);
#if defined(SQL_REMOVE_SHOWDEBUG)
#define SqlStmt_ShowDebug(self) (void)0
#else
-#define SqlStmt_ShowDebug(self) SQL->StmtShowDebug_(self, __FILE__, __LINE__)
-#endif
/// Shows debug information (with statement).
-
-
-
-
-
+#define SqlStmt_ShowDebug(self) (SQL->StmtShowDebug_((self), __FILE__, __LINE__))
+#endif
void Sql_Init(void);
-
#endif /* _COMMON_SQL_H_ */
diff --git a/src/common/strlib.h b/src/common/strlib.h
index 5ef455a0e..0c3b0a486 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -168,28 +168,28 @@ void strlib_defaults(void);
/* the purpose of these macros is simply to not make calling them be an annoyance */
#ifndef STRLIB_C
- #define jstrescape(pt) strlib->jstrescape(pt)
- #define jstrescapecpy(pt,spt) strlib->jstrescapecpy(pt,spt)
- #define jmemescapecpy(pt,spt,size) strlib->jmemescapecpy(pt,spt,size)
- #define remove_control_chars(str) strlib->remove_control_chars(str)
- #define trim(str) strlib->trim(str)
- #define normalize_name(str,delims) strlib->normalize_name(str,delims)
- #define stristr(haystack,needle) strlib->stristr(haystack,needle)
+ #define jstrescape(pt) (strlib->jstrescape(pt))
+ #define jstrescapecpy(pt,spt) (strlib->jstrescapecpy((pt),(spt)))
+ #define jmemescapecpy(pt,spt,size) (strlib->jmemescapecpy((pt),(spt),(size)))
+ #define remove_control_chars(str) (strlib->remove_control_chars(str))
+ #define trim(str) (strlib->trim(str))
+ #define normalize_name(str,delims) (strlib->normalize_name((str),(delims)))
+ #define stristr(haystack,needle) (strlib->stristr((haystack),(needle)))
#if !(defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400) && !defined(HAVE_STRNLEN)
- #define strnln(string,maxlen) strlib->strnlen(string,maxlen)
+ #define strnln(string,maxlen) (strlib->strnlen((string),(maxlen)))
#endif
#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200
- #define strtoull(str,endptr,base) strlib->strtoull(str,endptr,base)
+ #define strtoull(str,endptr,base) (strlib->strtoull((str),(endptr),(base)))
#endif
- #define e_mail_check(email) strlib->e_mail_check(email)
- #define config_switch(str) strlib->config_switch(str)
- #define safestrncpy(dst,src,n) strlib->safestrncpy(dst,src,n)
- #define safestrnlen(string,maxlen) strlib->safestrnlen(string,maxlen)
- #define safesnprintf(buf,sz,fmt,...) strlib->safesnprintf(buf,sz,fmt,##__VA_ARGS__)
- #define strline(str,pos) strlib->strline(str,pos)
- #define bin2hex(output,input,count) strlib->bin2hex(output,input,count)
+ #define e_mail_check(email) (strlib->e_mail_check(email))
+ #define config_switch(str) (strlib->config_switch(str))
+ #define safestrncpy(dst,src,n) (strlib->safestrncpy((dst),(src),(n)))
+ #define safestrnlen(string,maxlen) (strlib->safestrnlen((string),(maxlen)))
+ #define safesnprintf(buf,sz,fmt,...) (strlib->safesnprintf((buf),(sz),(fmt),##__VA_ARGS__))
+ #define strline(str,pos) (strlib->strline((str),(pos)))
+ #define bin2hex(output,input,count) (strlib->bin2hex((output),(input),(count)))
#endif /* STRLIB_C */
#endif /* _STRLIB_H_ */
diff --git a/src/common/timer.h b/src/common/timer.h
index 4a2bebe7d..9aa29861e 100644
--- a/src/common/timer.h
+++ b/src/common/timer.h
@@ -8,7 +8,7 @@
#define DIFF_TICK(a,b) ((a)-(b))
#define DIFF_TICK32(a,b) ((int32)((a)-(b)))
-#define INVALID_TIMER -1
+#define INVALID_TIMER (-1)
// timer flags
enum {
diff --git a/src/common/utils.h b/src/common/utils.h
index 3e1463d6b..719e1e533 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -20,7 +20,7 @@ void findfile(const char *p, const char *pat, void (func)(const char*));
bool exists(const char* filename);
//Caps values to min/max
-#define cap_value(a, min, max) ((a >= max) ? max : (a <= min) ? min : a)
+#define cap_value(a, min, max) (((a) >= (max)) ? (max) : ((a) <= (min)) ? (min) : (a))
/// calculates the value of A / B, in percent (rounded down)
unsigned int get_percentage(const unsigned int A, const unsigned int B);