diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/HPM.c | 46 | ||||
-rw-r--r-- | src/common/cbasetypes.h | 12 | ||||
-rw-r--r-- | src/common/console.c | 43 | ||||
-rw-r--r-- | src/common/core.c | 39 | ||||
-rw-r--r-- | src/common/db.c | 25 | ||||
-rw-r--r-- | src/common/des.c | 7 | ||||
-rw-r--r-- | src/common/ers.c | 16 | ||||
-rw-r--r-- | src/common/grfio.c | 24 | ||||
-rw-r--r-- | src/common/mapindex.c | 35 | ||||
-rw-r--r-- | src/common/mutex.c | 12 | ||||
-rw-r--r-- | src/common/socket.c | 31 | ||||
-rw-r--r-- | src/common/sql.c | 26 | ||||
-rw-r--r-- | src/common/strlib.c | 1 | ||||
-rw-r--r-- | src/common/sysinfo.c | 84 | ||||
-rw-r--r-- | src/common/utils.c | 29 | ||||
-rw-r--r-- | src/plugins/db2sql.c | 2 |
16 files changed, 317 insertions, 115 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index dbe121940..c34828010 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -103,6 +103,7 @@ void hplugin_export_symbol(void *value, const char *name) void *hplugin_import_symbol(char *name, unsigned int pID) { int i; + nullpo_retr(NULL, name); ARR_FIND(0, VECTOR_LENGTH(HPM->symbols), i, strcmp(VECTOR_INDEX(HPM->symbols, i)->name, name) == 0); if (i != VECTOR_LENGTH(HPM->symbols)) @@ -133,6 +134,7 @@ bool hplugin_iscompatible(char* version) { bool hplugin_exists(const char *filename) { int i; + nullpo_retr(false, filename); for (i = 0; i < VECTOR_LENGTH(HPM->plugins); i++) { if (strcmpi(VECTOR_INDEX(HPM->plugins, i)->filename,filename) == 0) return true; @@ -259,6 +261,7 @@ void hplugins_addToHPData(enum HPluginDataTypes type, uint32 pluginID, struct hp return; } store = *storeptr; + nullpo_retv(store); /* duplicate check */ ARR_FIND(0, VECTOR_LENGTH(store->entries), i, VECTOR_INDEX(store->entries, i)->pluginID == pluginID && VECTOR_INDEX(store->entries, i)->classid == classid); @@ -447,7 +450,8 @@ bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *na return true; } -struct hplugin *hplugin_load(const char* filename) { +struct hplugin *hplugin_load(const char* filename) +{ struct hplugin *plugin; struct hplugin_info *info; struct HPMi_interface **HPMi; @@ -596,6 +600,7 @@ struct hplugin *hplugin_load(const char* filename) { void hplugin_unload(struct hplugin* plugin) { int i; + nullpo_retv(plugin); if (plugin->filename) aFree(plugin->filename); if (plugin->dll) @@ -622,7 +627,8 @@ CMDLINEARG(loadplugin) /** * Reads the plugin configuration and loads the plugins as necessary. */ -void hplugins_config_read(void) { +void hplugins_config_read(void) +{ struct config_t plugins_conf; struct config_setting_t *plist = NULL; const char *config_filename = "conf/plugins.conf"; // FIXME hardcoded name @@ -788,6 +794,7 @@ const char *HPM_file2ptr(const char *file) { int i; + nullpo_retr(NULL, file); ARR_FIND(0, HPM->filenames.count, i, HPM->filenames.data[i].addr == file); if (i != HPM->filenames.count) { return HPM->filenames.data[i].name; @@ -801,19 +808,29 @@ const char *HPM_file2ptr(const char *file) return HPM->filenames.data[i].name; } -void* HPM_mmalloc(size_t size, const char *file, int line, const char *func) { + +void* HPM_mmalloc(size_t size, const char *file, int line, const char *func) +{ return iMalloc->malloc(size,HPM_file2ptr(file),line,func); } -void* HPM_calloc(size_t num, size_t size, const char *file, int line, const char *func) { + +void* HPM_calloc(size_t num, size_t size, const char *file, int line, const char *func) +{ return iMalloc->calloc(num,size,HPM_file2ptr(file),line,func); } -void* HPM_realloc(void *p, size_t size, const char *file, int line, const char *func) { + +void* HPM_realloc(void *p, size_t size, const char *file, int line, const char *func) +{ return iMalloc->realloc(p,size,HPM_file2ptr(file),line,func); } -void* HPM_reallocz(void *p, size_t size, const char *file, int line, const char *func) { + +void* HPM_reallocz(void *p, size_t size, const char *file, int line, const char *func) +{ return iMalloc->reallocz(p,size,HPM_file2ptr(file),line,func); } -char* HPM_astrdup(const char *p, const char *file, int line, const char *func) { + +char* HPM_astrdup(const char *p, const char *file, int line, const char *func) +{ return iMalloc->astrdup(p,HPM_file2ptr(file),line,func); } @@ -849,6 +866,7 @@ bool hplugins_get_battle_conf(const char *w1, int *value) { int i; + nullpo_retr(w1, value); nullpo_retr(false, value); ARR_FIND(0, VECTOR_LENGTH(HPM->config_listeners[HPCT_BATTLE]), i, strcmpi(w1, VECTOR_INDEX(HPM->config_listeners[HPCT_BATTLE], i).key) == 0); @@ -1012,9 +1030,11 @@ void hplugin_data_store_create(struct hplugin_data_store **storeptr, enum HPlugi /** * Called by HPM->DataCheck on a plugins incoming data, ensures data structs in use are matching! **/ -bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, char *name) { +bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, char *name) +{ unsigned int i, j; + nullpo_retr(false, src); if (version != datacheck_version) { ShowError("HPMDataCheck:%s: DataCheck API version mismatch %d != %d\n", name, datacheck_version, version); return false; @@ -1039,7 +1059,8 @@ bool HPM_DataCheck(struct s_HPMDataCheck *src, unsigned int size, int version, c return true; } -void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, int version) { +void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, int version) +{ unsigned int i; datacheck_version = version; @@ -1055,11 +1076,13 @@ void HPM_datacheck_init(const struct s_HPMDataCheck *src, unsigned int length, i } } -void HPM_datacheck_final(void) { +void HPM_datacheck_final(void) +{ db_destroy(datacheck_db); } -void hpm_init(void) { +void hpm_init(void) +{ int i; datacheck_db = NULL; datacheck_data = NULL; @@ -1151,6 +1174,7 @@ void hpm_final(void) return; } + void hpm_defaults(void) { HPM = &HPM_s; diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 33d617b13..98c3552c4 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -291,12 +291,12 @@ typedef uintptr_t uintptr; #define GCC_VERSION 0 #endif -// Pragma macro only enabled on gcc >= 4.5 or clang - borrowed from Mana Plus -#if defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40500) -#define PRAGMA_GCC45(str) _Pragma(#str) -#else // ! defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40500) -#define PRAGMA_GCC45(str) -#endif // ! defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40500) +// Pragma macro only enabled on gcc >= 4.6 or clang - borrowed from Mana Plus +#if defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40600) +#define PRAGMA_GCC46(str) _Pragma(#str) +#else // ! defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40600) +#define PRAGMA_GCC46(str) +#endif // ! defined(__GNUC__) && (defined(__clang__) || GCC_VERSION >= 40600) // fallthrough attribute only enabled on gcc >= 7.0 #if defined(__GNUC__) && (GCC_VERSION >= 70000) diff --git a/src/common/console.c b/src/common/console.c index f1b4523e2..654f26cb3 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -68,7 +68,8 @@ struct { /*====================================== * CORE : Display title *--------------------------------------*/ -void display_title(void) { +void display_title(void) +{ const char *vcstype = sysinfo->vcstype(); ShowMessage("\n"); @@ -130,21 +131,24 @@ int console_parse_key_pressed(void) /** * Stops server **/ -CPCMD_C(exit,server) { +CPCMD_C(exit, server) +{ core->runflag = 0; } /** * Displays ERS-related statistics (Entry Reusage System) **/ -CPCMD_C(ers_report,server) { +CPCMD_C(ers_report, server) +{ ers_report(); } /** * Displays memory usage **/ -CPCMD_C(mem_report,server) { +CPCMD_C(mem_report, server) +{ #ifdef USE_MEMMGR memmgr_report(line?atoi(line):0); #endif @@ -171,7 +175,8 @@ CPCMD(help) * [Ind/Hercules] * Displays current malloc usage */ -CPCMD_C(malloc_usage,server) { +CPCMD_C(malloc_usage, server) +{ unsigned int val = (unsigned int)iMalloc->usage(); ShowInfo("malloc_usage: %.2f MB\n",(double)(val)/1024); } @@ -180,7 +185,8 @@ CPCMD_C(malloc_usage,server) { * Skips an sql update * Usage: sql update skip UPDATE-FILE.sql **/ -CPCMD_C(skip,update) { +CPCMD_C(skip, update) +{ if( !line ) { ShowDebug("usage example: sql update skip 2013-02-14--16-15.sql\n"); return; @@ -311,6 +317,7 @@ void console_parse_create(char *name, CParseFunc func) char sublist[CP_CMD_LENGTH * 5]; struct CParseEntry *cmd; + nullpo_retv(name); safestrncpy(sublist, name, CP_CMD_LENGTH * 5); tok = strtok(sublist,":"); @@ -364,6 +371,7 @@ void console_parse_list_subs(struct CParseEntry *cmd, unsigned char depth) { int i; char msg[CP_CMD_LENGTH * 2]; + nullpo_retv(cmd); Assert_retv(cmd->type == CPET_CATEGORY); for (i = 0; i < VECTOR_LENGTH(cmd->u.children); i++) { struct CParseEntry *child = VECTOR_INDEX(cmd->u.children, i); @@ -391,6 +399,7 @@ void console_parse_sub(char *line) char sublist[CP_CMD_LENGTH * 5]; int i; + nullpo_retv(line); memcpy(bline, line, 200); tok = strtok(line, " "); @@ -444,9 +453,12 @@ void console_parse_sub(char *line) } ShowError("Is only a category, type '"CL_WHITE"%s help"CL_RESET"' to list its subcommands\n",sublist); } -void console_parse(char* line) { + +void console_parse(char *line) +{ int c, i = 0, len = MAX_CONSOLE_INPUT - 1;/* we leave room for the \0 :P */ + nullpo_retv(line); while( (c = fgetc(stdin)) != EOF ) { if( --len == 0 ) break; @@ -458,7 +470,9 @@ void console_parse(char* line) { line[i++] = '\0'; } -void *cThread_main(void *x) { + +void *cThread_main(void *x) +{ while( console->input->ptstate ) {/* loopx */ if( console->input->key_pressed() ) { char input[MAX_CONSOLE_INPUT]; @@ -483,7 +497,9 @@ void *cThread_main(void *x) { return NULL; } -int console_parse_timer(int tid, int64 tick, int id, intptr_t data) { + +int console_parse_timer(int tid, int64 tick, int id, intptr_t data) +{ int i; EnterSpinLock(console->input->ptlock); for(i = 0; i < cinput.count; i++) { @@ -494,7 +510,9 @@ int console_parse_timer(int tid, int64 tick, int id, intptr_t data) { mutex->cond_signal(console->input->ptcond); return 0; } -void console_parse_final(void) { + +void console_parse_final(void) +{ if( console->input->ptstate ) { InterlockedDecrement(&console->input->ptstate); mutex->cond_signal(console->input->ptcond); @@ -506,7 +524,9 @@ void console_parse_final(void) { mutex->destroy(console->input->ptmutex); } } -void console_parse_init(void) { + +void console_parse_init(void) +{ cinput.count = 0; console->input->ptstate = 1; @@ -524,6 +544,7 @@ void console_parse_init(void) { timer->add_func_list(console->input->parse_timer, "console_parse_timer"); timer->add_interval(timer->gettick() + 1000, console->input->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */ } + void console_setSQL(struct Sql *SQL_handle) { console->input->SQL = SQL_handle; diff --git a/src/common/core.c b/src/common/core.c index 63123dfea..74c63a6d6 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -100,7 +100,8 @@ struct core_interface *core = &core_s; #ifndef POSIX #define compat_signal(signo, func) signal((signo), (func)) #else -sigfunc *compat_signal(int signo, sigfunc *func) { +sigfunc *compat_signal(int signo, sigfunc *func) +{ struct sigaction sact, oact; sact.sa_handler = func; @@ -121,7 +122,8 @@ sigfunc *compat_signal(int signo, sigfunc *func) { * CORE : Console events for Windows *--------------------------------------*/ #ifdef _WIN32 -static BOOL WINAPI console_handler(DWORD c_event) { +static BOOL WINAPI console_handler(DWORD c_event) +{ switch(c_event) { case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: @@ -137,7 +139,8 @@ static BOOL WINAPI console_handler(DWORD c_event) { return TRUE; } -static void cevents_init(void) { +static void cevents_init(void) +{ if (SetConsoleCtrlHandler(console_handler,TRUE)==FALSE) ShowWarning ("Unable to install the console handler!\n"); } @@ -146,7 +149,8 @@ static void cevents_init(void) { /*====================================== * CORE : Signal Sub Function *--------------------------------------*/ -static void sig_proc(int sn) { +static void sig_proc(int sn) +{ static int is_called = 0; switch (sn) { @@ -179,7 +183,8 @@ static void sig_proc(int sn) { } } -void signals_init (void) { +void signals_init (void) +{ compat_signal(SIGTERM, sig_proc); compat_signal(SIGINT, sig_proc); #ifndef _DEBUG // need unhandled exceptions to debug on Windows @@ -245,7 +250,8 @@ bool usercheck(void) return true; } -void core_defaults(void) { +void core_defaults(void) +{ nullpo_defaults(); #ifndef MINICORE hpm_defaults(); @@ -271,16 +277,20 @@ void core_defaults(void) { thread_defaults(); #endif } + /** * Returns the source (core or plugin name) for the given command-line argument */ -const char *cmdline_arg_source(struct CmdlineArgData *arg) { +const char *cmdline_arg_source(struct CmdlineArgData *arg) +{ #ifdef MINICORE return "core"; #else // !MINICORE + nullpo_retr(NULL, arg); return HPM->pid2name(arg->pluginID); #endif // MINICORE } + /** * Defines a command line argument. * @@ -292,9 +302,11 @@ const char *cmdline_arg_source(struct CmdlineArgData *arg) { * @param options options associated to the command-line argument. @see enum cmdline_options. * @return the success status. */ -bool cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options) { +bool cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options) +{ struct CmdlineArgData *data = NULL; + nullpo_retr(false, name); VECTOR_ENSURE(cmdline->args_data, 1, 1); VECTOR_PUSHZEROED(cmdline->args_data); data = &VECTOR_LAST(cmdline->args_data); @@ -310,6 +322,7 @@ bool cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, Cm return true; } + /** * Help screen to be displayed by '--help'. */ @@ -333,6 +346,7 @@ static CMDLINEARG(help) } return false; } + /** * Info screen to be displayed by '--version'. */ @@ -343,6 +357,7 @@ static CMDLINEARG(version) ShowInfo("Open "CL_WHITE"readme.txt"CL_RESET" for more information.\n"); return false; } + /** * Checks if there is a value available for the current argument * @@ -360,6 +375,7 @@ bool cmdline_arg_next_value(const char *name, int current_arg, int argc) return true; } + /** * Executes the command line arguments handlers. * @@ -381,6 +397,8 @@ bool cmdline_arg_next_value(const char *name, int current_arg, int argc) int cmdline_exec(int argc, char **argv, unsigned int options) { int count = 0, i; + + nullpo_ret(argv); for (i = 1; i < argc; i++) { int j; struct CmdlineArgData *data = NULL; @@ -423,6 +441,7 @@ int cmdline_exec(int argc, char **argv, unsigned int options) } return count; } + /** * Defines the global command-line arguments. */ @@ -466,10 +485,12 @@ void cmdline_defaults(void) cmdline->arg_next_value = cmdline_arg_next_value; cmdline->arg_source = cmdline_arg_source; } + /*====================================== * CORE : MAINROUTINE *--------------------------------------*/ -int main (int argc, char **argv) { +int main (int argc, char **argv) +{ int retval = EXIT_SUCCESS; {// initialize program arguments char *p1 = SERVER_NAME = argv[0]; diff --git a/src/common/db.c b/src/common/db.c index 0c7bc2ae0..5f69e2f70 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -93,6 +93,7 @@ #include "common/ers.h" #include "common/memmgr.h" #include "common/mmo.h" +#include "common/nullpo.h" #include "common/showmsg.h" #include "common/strlib.h" @@ -2795,7 +2796,8 @@ void *db_data2ptr(struct DBData *data) * @public * @see #db_final(void) */ -void db_init(void) { +void db_init(void) +{ db_iterator_ers = ers_new(sizeof(struct DBIterator_impl),"db.c::db_iterator_ers",ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK); db_alloc_ers = ers_new(sizeof(struct DBMap_impl),"db.c::db_alloc_ers",ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK); ers_chunk_size(db_alloc_ers, 50); @@ -2907,7 +2909,7 @@ void db_final(void) } // Link DB System - jAthena -void linkdb_insert( struct linkdb_node** head, void *key, void* data) +void linkdb_insert(struct linkdb_node **head, void *key, void *data) { struct linkdb_node *node; if( head == NULL ) return ; @@ -2928,7 +2930,8 @@ void linkdb_insert( struct linkdb_node** head, void *key, void* data) node->data = data; } -void linkdb_vforeach( struct linkdb_node** head, LinkDBFunc func, va_list ap) { +void linkdb_vforeach(struct linkdb_node **head, LinkDBFunc func, va_list ap) +{ struct linkdb_node *node; if( head == NULL ) return; node = *head; @@ -2941,14 +2944,15 @@ void linkdb_vforeach( struct linkdb_node** head, LinkDBFunc func, va_list ap) { } } -void linkdb_foreach( struct linkdb_node** head, LinkDBFunc func, ...) { +void linkdb_foreach(struct linkdb_node **head, LinkDBFunc func, ...) +{ va_list ap; va_start(ap, func); linkdb_vforeach(head, func, ap); va_end(ap); } -void* linkdb_search( struct linkdb_node** head, void *key) +void* linkdb_search(struct linkdb_node **head, void *key) { int n = 0; struct linkdb_node *node; @@ -2973,7 +2977,7 @@ void* linkdb_search( struct linkdb_node** head, void *key) return NULL; } -void* linkdb_erase( struct linkdb_node** head, void *key) +void* linkdb_erase(struct linkdb_node **head, void *key) { struct linkdb_node *node; if( head == NULL ) return NULL; @@ -2995,7 +2999,7 @@ void* linkdb_erase( struct linkdb_node** head, void *key) return NULL; } -void linkdb_replace( struct linkdb_node** head, void *key, void *data ) +void linkdb_replace(struct linkdb_node **head, void *key, void *data) { int n = 0; struct linkdb_node *node; @@ -3022,7 +3026,7 @@ void linkdb_replace( struct linkdb_node** head, void *key, void *data ) linkdb_insert( head, key, data ); } -void linkdb_final( struct linkdb_node** head ) +void linkdb_final(struct linkdb_node **head) { struct linkdb_node *node, *node2; if( head == NULL ) return ; @@ -3034,7 +3038,9 @@ void linkdb_final( struct linkdb_node** head ) } *head = NULL; } -void db_defaults(void) { + +void db_defaults(void) +{ DB = &DB_s; DB->alloc = db_alloc; DB->custom_release = db_custom_release; @@ -3055,5 +3061,4 @@ void db_defaults(void) { DB->ui2key = db_ui2key; DB->i642key = db_i642key; DB->ui642key = db_ui642key; - } diff --git a/src/common/des.c b/src/common/des.c index c680610e9..73297ab70 100644 --- a/src/common/des.c +++ b/src/common/des.c @@ -23,6 +23,7 @@ #include "des.h" #include "common/cbasetypes.h" +#include "common/nullpo.h" /** @file * Implementation of the des interface. @@ -54,6 +55,7 @@ static void des_IP(struct des_bit64 *src) struct des_bit64 tmp = {{0}}; int i; + nullpo_retv(src); for(i = 0; i < ARRAYLENGTH(ip_table); ++i) { uint8_t j = ip_table[i] - 1; if (src->b[(j >> 3) & 7] & mask[j & 7]) @@ -81,6 +83,7 @@ static void des_FP(struct des_bit64 *src) struct des_bit64 tmp = {{0}}; int i; + nullpo_retv(src); for (i = 0; i < ARRAYLENGTH(fp_table); ++i) { uint8_t j = fp_table[i] - 1; if (src->b[(j >> 3) & 7] & mask[j & 7]) @@ -119,6 +122,7 @@ static void des_E(struct des_bit64 *src) tmp.b[i / 6 + 0] |= mask[i % 6]; } #endif + nullpo_retv(src); // optimized tmp.b[0] = ((src->b[7]<<5) | (src->b[4]>>3)) & 0x3f; // ..0 vutsr tmp.b[1] = ((src->b[4]<<1) | (src->b[5]>>7)) & 0x3f; // ..srqpo n @@ -150,6 +154,7 @@ static void des_TP(struct des_bit64 *src) struct des_bit64 tmp = {{0}}; int i; + nullpo_retv(src); for (i = 0; i < ARRAYLENGTH(tp_table); ++i) { uint8_t j = tp_table[i] - 1; if (src->b[(j >> 3) + 0] & mask[j & 7]) @@ -194,6 +199,7 @@ static void des_SBOX(struct des_bit64 *src) struct des_bit64 tmp = {{0}}; int i; + nullpo_retv(src); for (i = 0; i < ARRAYLENGTH(s_table); ++i) { tmp.b[i] = (s_table[i][src->b[i*2+0]] & 0xf0) | (s_table[i][src->b[i*2+1]] & 0x0f); @@ -214,6 +220,7 @@ static void des_RoundFunction(struct des_bit64 *src) des_SBOX(&tmp); des_TP(&tmp); + nullpo_retv(src); src->b[0] ^= tmp.b[4]; src->b[1] ^= tmp.b[5]; src->b[2] ^= tmp.b[6]; diff --git a/src/common/ers.c b/src/common/ers.c index 8970fefc2..3e1cdc25b 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -149,7 +149,8 @@ static struct ers_instance_t *InstanceList = NULL; /** * @param Options the options from the instance seeking a cache, we use it to give it a cache with matching configuration **/ -static ers_cache_t *ers_find_cache(unsigned int size, enum ERSOptions Options) { +static ers_cache_t *ers_find_cache(unsigned int size, enum ERSOptions Options) +{ ers_cache_t *cache; for (cache = CacheList; cache; cache = cache->Next) @@ -187,6 +188,7 @@ static void ers_free_cache(ers_cache_t *cache, bool remove) { unsigned int i; + nullpo_retv(cache); for (i = 0; i < cache->Used; i++) aFree(cache->Blocks[i]); @@ -307,7 +309,8 @@ static void ers_obj_destroy(ERS *self) aFree(instance); } -void ers_cache_size(ERS *self, unsigned int new_size) { +void ers_cache_size(ERS *self, unsigned int new_size) +{ struct ers_instance_t *instance = (struct ers_instance_t *)self; nullpo_retv(instance); @@ -319,10 +322,11 @@ void ers_cache_size(ERS *self, unsigned int new_size) { instance->Cache->ChunkSize = new_size; } - ERS *ers_new(uint32 size, char *name, enum ERSOptions options) { struct ers_instance_t *instance; + + nullpo_retr(NULL, name); CREATE(instance,struct ers_instance_t, 1); size += sizeof(struct ers_list); @@ -359,7 +363,8 @@ ERS *ers_new(uint32 size, char *name, enum ERSOptions options) return &instance->VTable; } -void ers_report(void) { +void ers_report(void) +{ ers_cache_t *cache; unsigned int cache_c = 0, blocks_u = 0, blocks_a = 0, memory_b = 0, memory_t = 0; #ifdef DEBUG @@ -403,7 +408,8 @@ void ers_report(void) { /** * Call on shutdown to clear remaining entries **/ -void ers_final(void) { +void ers_final(void) +{ struct ers_instance_t *instance = InstanceList, *next; while( instance ) { diff --git a/src/common/grfio.c b/src/common/grfio.c index 0a9708f17..fba3dda86 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -86,11 +86,13 @@ struct grfio_interface *grfio; // little endian char array to uint conversion static unsigned int getlong(unsigned char *p) { + nullpo_ret(p); return (p[0] << 0 | p[1] << 8 | p[2] << 16 | p[3] << 24); } static void NibbleSwap(unsigned char *src, int len) { + nullpo_retv(src); while (len > 0) { *src = (*src >> 4) | (*src << 4); ++src; @@ -135,6 +137,7 @@ static void grf_shuffle_enc(struct des_bit64 *src) { struct des_bit64 out; + nullpo_retv(src); out.b[0] = src->b[3]; out.b[1] = src->b[4]; out.b[2] = src->b[5]; @@ -152,6 +155,7 @@ static void grf_shuffle_dec(struct des_bit64 *src) { struct des_bit64 out; + nullpo_retv(src); out.b[0] = src->b[3]; out.b[1] = src->b[4]; out.b[2] = src->b[6]; @@ -175,6 +179,7 @@ static void grf_decode_header(unsigned char *buf, size_t len) struct des_bit64 *p = (struct des_bit64 *)buf; size_t nblocks = len / sizeof(struct des_bit64); size_t i; + nullpo_retv(buf); // first 20 blocks are all des-encrypted for (i = 0; i < 20 && i < nblocks; ++i) @@ -197,6 +202,7 @@ static void grf_decode_full(unsigned char *buf, size_t len, int cycle) int dcycle, scycle; size_t i, j; + nullpo_retv(buf); // first 20 blocks are all des-encrypted for (i = 0; i < 20 && i < nblocks; ++i) des->decrypt_block(&p[i]); @@ -314,6 +320,7 @@ static void hashinit(void) static int grf_filehash(const char *fname) { uint32 hash = 0; + nullpo_ret(fname); while (*fname != '\0') { hash = (hash<<1) + (hash>>7)*9 + TOLOWER(*fname); fname++; @@ -396,7 +403,9 @@ static struct grf_filelist *grfio_filelist_add(struct grf_filelist *entry) */ static struct grf_filelist *grfio_filelist_modify(struct grf_filelist *entry) { - struct grf_filelist *fentry = grfio_filelist_find(entry->fn); + struct grf_filelist *fentry; + nullpo_retr(NULL, entry); + fentry = grfio_filelist_find(entry->fn); if (fentry != NULL) { int tmp = fentry->next; memcpy(fentry, entry, sizeof(struct grf_filelist)); @@ -434,6 +443,7 @@ static void grfio_localpath_create(char *buffer, size_t size, const char *filena int i; size_t len; + nullpo_retv(buffer); len = strlen(data_dir); if (data_dir[0] == '\0' || data_dir[len-1] == '/' || data_dir[len-1] == '\\') @@ -553,6 +563,7 @@ void *grfio_reads(const char *fname, int *size) static char *grfio_decode_filename(unsigned char *buf, int len) { int i; + nullpo_retr(NULL, buf); for (i = 0; i < len; i += 8) { NibbleSwap(&buf[i],8); des->decrypt(&buf[i],8); @@ -568,7 +579,9 @@ static char *grfio_decode_filename(unsigned char *buf, int len) */ static bool grfio_is_full_encrypt(const char *fname) { - const char *ext = strrchr(fname, '.'); + const char *ext; + nullpo_retr(false, fname); + ext = strrchr(fname, '.'); if (ext != NULL) { static const char *extensions[] = { ".gnd", ".gat", ".act", ".str" }; int i; @@ -594,8 +607,10 @@ static int grfio_entryread(const char *grfname, int gentry) unsigned char grf_header[0x2e] = { 0 }; int entry,entrys,ofs,grf_version; unsigned char *grf_filelist; + FILE *fp; - FILE *fp = fopen(grfname, "rb"); + nullpo_retr(1, grfname); + fp = fopen(grfname, "rb"); if (fp == NULL) { ShowWarning("GRF data file not found: '%s'\n", grfname); return 1; // 1:not found error @@ -764,6 +779,7 @@ static bool grfio_parse_restable_row(const char *row) char local[256]; struct grf_filelist *entry = NULL; + nullpo_retr(false, row); if (sscanf(row, "%255[^#\r\n]#%255[^#\r\n]#", w1, w2) != 2) return false; @@ -854,6 +870,7 @@ static void grfio_resourcecheck(void) */ static int grfio_add(const char *fname) { + nullpo_retr(1, fname); if (gentry_entrys >= gentry_maxentry) { #define GENTRY_ADDS 4 // The number increment of gentry_table entries gentry_maxentry += GENTRY_ADDS; @@ -899,6 +916,7 @@ void grfio_init(const char *fname) FILE *data_conf; int grf_num = 0; + nullpo_retv(fname); hashinit(); // hash table initialization data_conf = fopen(fname, "r"); diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 5b0f6169b..c09e6260d 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -25,6 +25,7 @@ #include "common/cbasetypes.h" #include "common/db.h" #include "common/mmo.h" +#include "common/nullpo.h" #include "common/showmsg.h" #include "common/strlib.h" @@ -37,11 +38,14 @@ struct mapindex_interface *mapindex; /// Retrieves the map name from 'string' (removing .gat extension if present). /// Result gets placed either into 'buf' or in a static local buffer. -const char* mapindex_getmapname(const char* string, char* output) { +const char* mapindex_getmapname(const char* string, char* output) +{ static char buf[MAP_NAME_LENGTH]; char* dest = (output != NULL) ? output : buf; - size_t len = strnlen(string, MAP_NAME_LENGTH_EXT); + size_t len; + nullpo_retr(buf, string); + len = strnlen(string, MAP_NAME_LENGTH_EXT); if (len == MAP_NAME_LENGTH_EXT) { ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!\n", 2*MAP_NAME_LENGTH_EXT, string); len--; @@ -58,12 +62,15 @@ const char* mapindex_getmapname(const char* string, char* output) { /// Retrieves the map name from 'string' (adding .gat extension if not already present). /// Result gets placed either into 'buf' or in a static local buffer. -const char* mapindex_getmapname_ext(const char* string, char* output) { +const char* mapindex_getmapname_ext(const char* string, char* output) +{ static char buf[MAP_NAME_LENGTH_EXT]; char* dest = (output != NULL) ? output : buf; size_t len; + nullpo_retr(buf, string); + safestrncpy(buf,string, sizeof(buf)); sscanf(string, "%*[^#]%*[#]%15s", buf); @@ -87,7 +94,8 @@ const char* mapindex_getmapname_ext(const char* string, char* output) { /// Adds a map to the specified index /// Returns 1 if successful, 0 otherwise -int mapindex_addmap(int index, const char* name) { +int mapindex_addmap(int index, const char* name) +{ char map_name[MAP_NAME_LENGTH]; if (index == -1){ @@ -128,7 +136,8 @@ int mapindex_addmap(int index, const char* name) { return index; } -unsigned short mapindex_name2id(const char* name) { +unsigned short mapindex_name2id(const char* name) +{ int i; char map_name[MAP_NAME_LENGTH]; @@ -141,7 +150,8 @@ unsigned short mapindex_name2id(const char* name) { return 0; } -const char *mapindex_id2name_sub(uint16 id, const char *file, int line, const char *func) { +const char *mapindex_id2name_sub(uint16 id, const char *file, int line, const char *func) +{ if (id >= MAX_MAPINDEX || !mapindex_exists(id)) { ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache. %s:%s:%d\n", id,file,func,line); return mapindex->list[0].name; // dummy empty string so that the callee doesn't crash @@ -149,7 +159,8 @@ const char *mapindex_id2name_sub(uint16 id, const char *file, int line, const ch return mapindex->list[id].name; } -int mapindex_init(void) { +int mapindex_init(void) +{ FILE *fp; char line[1024]; int last_index = -1; @@ -196,16 +207,20 @@ bool mapindex_check_default(void) return true; } -void mapindex_removemap(int index){ +void mapindex_removemap(int index) +{ + Assert_retv(index < MAX_MAPINDEX); strdb_remove(mapindex->db, mapindex->list[index].name); mapindex->list[index].name[0] = '\0'; } -void mapindex_final(void) { +void mapindex_final(void) +{ db_destroy(mapindex->db); } -void mapindex_defaults(void) { +void mapindex_defaults(void) +{ mapindex = &mapindex_s; /* TODO: place it in inter-server.conf? */ diff --git a/src/common/mutex.c b/src/common/mutex.c index bdc2fb4dc..464a54161 100644 --- a/src/common/mutex.c +++ b/src/common/mutex.c @@ -24,6 +24,7 @@ #include "common/cbasetypes.h" // for WIN32 #include "common/memmgr.h" +#include "common/nullpo.h" #include "common/showmsg.h" #include "common/timer.h" @@ -84,6 +85,7 @@ struct mutex_data *mutex_create(void) /// @copydoc mutex_interface::destroy() void mutex_destroy(struct mutex_data *m) { + nullpo_retv(m); #ifdef WIN32 DeleteCriticalSection(&m->hMutex); #else @@ -96,6 +98,7 @@ void mutex_destroy(struct mutex_data *m) /// @copydoc mutex_interface::lock() void mutex_lock(struct mutex_data *m) { + nullpo_retv(m); #ifdef WIN32 EnterCriticalSection(&m->hMutex); #else @@ -106,6 +109,7 @@ void mutex_lock(struct mutex_data *m) /// @copydoc mutex_interface::trylock() bool mutex_trylock(struct mutex_data *m) { + nullpo_retr(false, m); #ifdef WIN32 if (TryEnterCriticalSection(&m->hMutex) != FALSE) return true; @@ -119,6 +123,7 @@ bool mutex_trylock(struct mutex_data *m) /// @copydoc mutex_interface::unlock() void mutex_unlock(struct mutex_data *m) { + nullpo_retv(m); #ifdef WIN32 LeaveCriticalSection(&m->hMutex); #else @@ -152,6 +157,7 @@ struct cond_data *cond_create(void) /// @copydoc mutex_interface::cond_destroy() void cond_destroy(struct cond_data *c) { + nullpo_retv(c); #ifdef WIN32 CloseHandle(c->events[EVENT_COND_SIGNAL]); CloseHandle(c->events[EVENT_COND_BROADCAST]); @@ -171,6 +177,7 @@ void cond_wait(struct cond_data *c, struct mutex_data *m, sysint timeout_ticks) int result; bool is_last = false; + nullpo_retv(c); EnterCriticalSection(&c->waiters_lock); c->nWaiters++; LeaveCriticalSection(&c->waiters_lock); @@ -201,6 +208,7 @@ void cond_wait(struct cond_data *c, struct mutex_data *m, sysint timeout_ticks) mutex->lock(m); #else + nullpo_retv(m); if (timeout_ticks < 0) { pthread_cond_wait(&c->hCond, &m->hMutex); } else { @@ -221,6 +229,7 @@ void cond_signal(struct cond_data *c) #ifdef WIN32 # if 0 bool has_waiters = false; + nullpo_retv(c); EnterCriticalSection(&c->waiters_lock); if(c->nWaiters > 0) has_waiters = true; @@ -230,6 +239,7 @@ void cond_signal(struct cond_data *c) # endif // 0 SetEvent(c->events[EVENT_COND_SIGNAL]); #else + nullpo_retv(c); pthread_cond_signal(&c->hCond); #endif } @@ -240,6 +250,7 @@ void cond_broadcast(struct cond_data *c) #ifdef WIN32 # if 0 bool has_waiters = false; + nullpo_retv(c); EnterCriticalSection(&c->waiters_lock); if(c->nWaiters > 0) has_waiters = true; @@ -249,6 +260,7 @@ void cond_broadcast(struct cond_data *c) # endif // 0 SetEvent(c->events[EVENT_COND_BROADCAST]); #else + nullpo_retv(c); pthread_cond_broadcast(&c->hCond); #endif } diff --git a/src/common/socket.c b/src/common/socket.c index ea7bfab40..5f284587a 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -520,7 +520,8 @@ void flush_fifos(void) /*====================================== * CORE : Connection functions *--------------------------------------*/ -int connect_client(int listen_fd) { +int connect_client(int listen_fd) +{ int fd; struct sockaddr_in client_address; socklen_t len; @@ -647,7 +648,8 @@ int make_listen_bind(uint32 ip, uint16 port) return fd; } -int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) { +int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) +{ struct sockaddr_in remote_address = { 0 }; int fd; int result; @@ -817,9 +819,12 @@ int rfifoskip(int fd, size_t len) int wfifoset(int fd, size_t len) { size_t newreserve; - struct socket_data* s = sockt->session[fd]; + struct socket_data* s; - if (!sockt->session_is_valid(fd) || s->wdata == NULL) + if (!sockt->session_is_valid(fd)) + return 0; + s = sockt->session[fd]; + if (s == NULL || s->wdata == NULL) return 0; // we have written len bytes to the buffer already before calling WFIFOSET @@ -1199,7 +1204,8 @@ static int connect_check_(uint32 ip) /// Timer function. /// Deletes old connection history records. -static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) { +static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) +{ int clear = 0; int list = 0; struct connect_history *hist = NULL; @@ -1235,6 +1241,9 @@ int access_ipmask(const char *str, struct access_control *acc) uint32 ip; uint32 mask; + nullpo_ret(str); + nullpo_ret(acc); + if( strcmp(str,"all") == 0 ) { ip = 0; mask = 0; @@ -1736,9 +1745,11 @@ bool session_is_active(int fd) } // Resolves hostname into a numeric ip. -uint32 host2ip(const char* hostname) +uint32 host2ip(const char *hostname) { - struct hostent* h = gethostbyname(hostname); + struct hostent* h; + nullpo_ret(hostname); + h = gethostbyname(hostname); return (h != NULL) ? ntohl(*(uint32*)h->h_addr) : 0; } @@ -1771,7 +1782,8 @@ uint16 ntows(uint16 netshort) } /* [Ind/Hercules] - socket_datasync */ -void socket_datasync(int fd, bool send) { +void socket_datasync(int fd, bool send) +{ struct { unsigned int length;/* short is not enough for some */ } data_list[] = { @@ -2055,7 +2067,8 @@ void socket_net_config_read(const char *filename) return; } -void socket_defaults(void) { +void socket_defaults(void) +{ sockt = &sockt_s; sockt->fd_max = 0; diff --git a/src/common/sql.c b/src/common/sql.c index 7e3e2e46f..c80edbce4 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -144,6 +144,7 @@ int Sql_GetColumnNames(struct Sql *self, const char *table, char *out_buf, size_ size_t len; size_t off = 0; + nullpo_retr(SQL_ERROR, out_buf); if( self == NULL || SQL_ERROR == SQL->Query(self, "EXPLAIN `%s`", table) ) return SQL_ERROR; @@ -377,7 +378,8 @@ void Sql_ShowDebug_(struct Sql *self, const char *debug_file, const unsigned lon } /// Frees a Sql handle returned by Sql_Malloc. -void Sql_Free(struct Sql *self) { +void Sql_Free(struct Sql *self) +{ if( self ) { SQL->FreeResult(self); @@ -414,6 +416,7 @@ static enum enum_field_types Sql_P_SizeToMysqlIntType(int sz) /// @private static int Sql_P_BindSqlDataType(MYSQL_BIND* bind, enum SqlDataType buffer_type, void* buffer, size_t buffer_len, unsigned long* out_length, int8* out_is_null) { + nullpo_retr(SQL_ERROR, bind); memset(bind, 0, sizeof(MYSQL_BIND)); switch( buffer_type ) { @@ -494,7 +497,8 @@ static int Sql_P_BindSqlDataType(MYSQL_BIND* bind, enum SqlDataType buffer_type, /// Prints debug information about a field (type and length). /// /// @private -static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_types type, int is_unsigned, unsigned long length, const char* length_postfix) { +static void Sql_P_ShowDebugMysqlFieldInfo(const char* prefix, enum enum_field_types type, int is_unsigned, unsigned long length, const char* length_postfix) +{ const char *sign = (is_unsigned ? "UNSIGNED " : ""); const char *type_string = NULL; switch (type) { @@ -535,6 +539,7 @@ static void SqlStmt_P_ShowDebugTruncatedColumn(struct SqlStmt *self, size_t i) MYSQL_FIELD* field; MYSQL_BIND* column; + nullpo_retv(self); meta = mysql_stmt_result_metadata(self->stmt); field = mysql_fetch_field_direct(meta, (unsigned int)i); ShowSQL("DB error - data of field '%s' was truncated.\n", field->name); @@ -664,8 +669,8 @@ int SqlStmt_BindParam(struct SqlStmt *self, size_t idx, enum SqlDataType buffer_ if (idx >= self->max_params) return SQL_SUCCESS; // out of range - ignore -PRAGMA_GCC45(GCC diagnostic push) -PRAGMA_GCC45(GCC diagnostic ignored "-Wcast-qual") +PRAGMA_GCC46(GCC diagnostic push) +PRAGMA_GCC46(GCC diagnostic ignored "-Wcast-qual") /* * MySQL uses the same struct with a non-const buffer for both * parameters (input) and columns (output). @@ -673,7 +678,7 @@ PRAGMA_GCC45(GCC diagnostic ignored "-Wcast-qual") * dropping a const qualifier here. */ return Sql_P_BindSqlDataType(self->params+idx, buffer_type, (void *)buffer, buffer_len, NULL, NULL); -PRAGMA_GCC45(GCC diagnostic pop) +PRAGMA_GCC46(GCC diagnostic pop) } /// Executes the prepared statement. @@ -874,8 +879,10 @@ void SqlStmt_Free(struct SqlStmt *self) aFree(self); } } + /* receives mysql error codes during runtime (not on first-time-connects) */ -void hercules_mysql_error_handler(unsigned int ecode) { +void hercules_mysql_error_handler(unsigned int ecode) +{ switch( ecode ) { case 2003:/* Can't connect to MySQL (this error only happens here when failing to reconnect) */ if( mysql_reconnect_type == 1 ) { @@ -1041,10 +1048,13 @@ void Sql_HerculesUpdateSkip(struct Sql *self, const char *filename) return; } -void Sql_Init(void) { +void Sql_Init(void) +{ Sql_inter_server_read("conf/common/inter-server.conf", false); // FIXME: Hardcoded path } -void sql_defaults(void) { + +void sql_defaults(void) +{ SQL = &sql_s; SQL->Connect = Sql_Connect; diff --git a/src/common/strlib.c b/src/common/strlib.c index b67adb63c..75ce2a272 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -629,6 +629,7 @@ int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, i svstate.delim = delim; svstate.done = false; svstate.start = 0; + svstate.end = 0; // parse count = 0; diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c index aeb8d8e71..3c7e25a0c 100644 --- a/src/common/sysinfo.c +++ b/src/common/sysinfo.c @@ -31,6 +31,7 @@ #include "common/cbasetypes.h" #include "common/core.h" #include "common/memmgr.h" +#include "common/nullpo.h" #include "common/strlib.h" #include <stdio.h> // fopen @@ -237,11 +238,13 @@ enum windows_ver_suite { * @retval true if a revision was correctly detected. * @retval false if no revision was detected. out is set to NULL in this case. */ -bool sysinfo_svn_get_revision(char **out) { +bool sysinfo_svn_get_revision(char **out) +{ // Only include SVN support if detected it, or we're on MSVC #if !defined(SYSINFO_VCSTYPE) || SYSINFO_VCSTYPE == VCSTYPE_SVN || SYSINFO_VCSTYPE == VCSTYPE_UNKNOWN FILE *fp; + nullpo_ret(out); // subversion 1.7 uses a sqlite3 database // FIXME this is hackish at best... // - ignores database file structure @@ -291,6 +294,8 @@ bool sysinfo_svn_get_revision(char **out) { if (*out != NULL) return true; } +#else + nullpo_ret(out); #endif if (*out != NULL) aFree(*out); @@ -305,11 +310,13 @@ bool sysinfo_svn_get_revision(char **out) { * @retval true if a revision was correctly detected. * @retval false if no revision was detected. out is set to NULL in this case. */ -bool sysinfo_git_get_revision(char **out) { +bool sysinfo_git_get_revision(char **out) +{ // Only include Git support if we detected it, or we're on MSVC #if !defined(SYSINFO_VCSTYPE) || SYSINFO_VCSTYPE == VCSTYPE_GIT || SYSINFO_VCSTYPE == VCSTYPE_UNKNOWN char ref[128], filepath[128], line[128]; + nullpo_ret(out); strcpy(ref, "HEAD"); while (*ref) { @@ -334,6 +341,7 @@ bool sysinfo_git_get_revision(char **out) { if (*out != NULL) return true; #else + nullpo_ret(out); if (*out != NULL) aFree(*out); *out = NULL; @@ -351,7 +359,8 @@ typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); * * Once retrieved, the version string is stored into sysinfo->p->osversion. */ -void sysinfo_osversion_retrieve(void) { +void sysinfo_osversion_retrieve(void) +{ OSVERSIONINFOEX osvi; StringBuf buf; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); @@ -602,7 +611,8 @@ typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); * System info is not stored anywhere after retrieval * @see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx **/ -void sysinfo_systeminfo_retrieve( LPSYSTEM_INFO info ) { +void sysinfo_systeminfo_retrieve(LPSYSTEM_INFO info) +{ PGNSI pGNSI; // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. @@ -619,7 +629,8 @@ void sysinfo_systeminfo_retrieve( LPSYSTEM_INFO info ) { * Returns number of bytes in a memory page * Only needed when compiling with MSVC **/ -long sysinfo_getpagesize( void ) { +long sysinfo_getpagesize(void) +{ SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO)); @@ -633,7 +644,8 @@ long sysinfo_getpagesize( void ) { * Once retrieved, the name is stored into sysinfo->p->cpu and the * number of cores in sysinfo->p->cpucores. */ -void sysinfo_cpu_retrieve(void) { +void sysinfo_cpu_retrieve(void) +{ StringBuf buf; SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO)); @@ -669,7 +681,8 @@ void sysinfo_cpu_retrieve(void) { * * Once retrieved, the name is stored into sysinfo->p->arch. */ -void sysinfo_arch_retrieve(void) { +void sysinfo_arch_retrieve(void) +{ SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO)); @@ -697,7 +710,8 @@ void sysinfo_arch_retrieve(void) { * * Once retrieved, the value is stored in sysinfo->p->vcsrevision_src. */ -void sysinfo_vcsrevision_src_retrieve(void) { +void sysinfo_vcsrevision_src_retrieve(void) +{ if (sysinfo->p->vcsrevision_src != NULL) { aFree(sysinfo->p->vcsrevision_src); sysinfo->p->vcsrevision_src = NULL; @@ -721,7 +735,8 @@ void sysinfo_vcsrevision_src_retrieve(void) { * * Once retrieved, the value is stored in sysinfo->p->vcstype_name. */ -void sysinfo_vcstype_name_retrieve(void) { +void sysinfo_vcstype_name_retrieve(void) +{ if (sysinfo->p->vcstype_name != NULL) { aFree(sysinfo->p->vcstype_name); sysinfo->p->vcstype_name = NULL; @@ -750,7 +765,8 @@ void sysinfo_vcstype_name_retrieve(void) { * * Output example: "Linux", "Darwin", "Windows", etc. */ -const char *sysinfo_platform(void) { +const char *sysinfo_platform(void) +{ return sysinfo->p->platform; } @@ -768,7 +784,8 @@ const char *sysinfo_platform(void) { * Output example: "Windows 2008 Small Business Server", "OS X 10.8 Mountain Lion", * "Gentoo Base System Release 2.2", "Debian GNU/Linux 6.0.6 (squeeze)", etc. */ -const char *sysinfo_osversion(void) { +const char *sysinfo_osversion(void) +{ return sysinfo->p->osversion; } @@ -787,7 +804,8 @@ const char *sysinfo_osversion(void) { * "Intel(R) Xeon(R) CPU E5-1650 0 @ 3.20GHz", "Intel Core i7", * "x86 CPU, Family 6, Model 54, Stepping 1", etc. */ -const char *sysinfo_cpu(void) { +const char *sysinfo_cpu(void) +{ return sysinfo->p->cpu; } @@ -800,7 +818,8 @@ const char *sysinfo_cpu(void) { * * @return the number of CPU cores. */ -int sysinfo_cpucores(void) { +int sysinfo_cpucores(void) +{ return sysinfo->p->cpucores; } @@ -817,7 +836,8 @@ int sysinfo_cpucores(void) { * * Output example: "x86", "x86_64", "IA-64", "ARM", etc. */ -const char *sysinfo_arch(void) { +const char *sysinfo_arch(void) +{ return sysinfo->p->arch; } @@ -827,7 +847,8 @@ const char *sysinfo_arch(void) { * @retval true if this is a 64 bit build. * @retval false if this isn't a 64 bit build (i.e. it is a 32 bit build). */ -bool sysinfo_is64bit(void) { +bool sysinfo_is64bit(void) +{ #ifdef _LP64 return true; #else @@ -845,7 +866,8 @@ bool sysinfo_is64bit(void) { * Output example: "Microsoft Visual C++ 2012 (v170050727)", * "Clang v5.0.0", "MinGW32 v3.20", "GCC v4.7.3", etc. */ -const char *sysinfo_compiler(void) { +const char *sysinfo_compiler(void) +{ return sysinfo->p->compiler; } @@ -860,7 +882,8 @@ const char *sysinfo_compiler(void) { * * Output example: "-ggdb -O2 -flto -pipe -ffast-math ..." */ -const char *sysinfo_cflags(void) { +const char *sysinfo_cflags(void) +{ return sysinfo->p->cflags; } @@ -875,7 +898,8 @@ const char *sysinfo_cflags(void) { * * @see VCSTYPE_NONE, VCSTYPE_GIT, VCSTYPE_SVN, VCSTYPE_UNKNOWN */ -int sysinfo_vcstypeid(void) { +int sysinfo_vcstypeid(void) +{ return sysinfo->p->vcstype; } @@ -892,7 +916,8 @@ int sysinfo_vcstypeid(void) { * * Output example: "Git", "SVN", "Exported" */ -const char *sysinfo_vcstype(void) { +const char *sysinfo_vcstype(void) +{ return sysinfo->p->vcstype_name; } @@ -910,7 +935,8 @@ const char *sysinfo_vcstype(void) { * * Output example: Git: "9128feccf3bddda94a7f8a170305565416815b40", SVN: "17546" */ -const char *sysinfo_vcsrevision_src(void) { +const char *sysinfo_vcsrevision_src(void) +{ return sysinfo->p->vcsrevision_src; } @@ -926,7 +952,8 @@ const char *sysinfo_vcsrevision_src(void) { * * Output example: Git: "9128feccf3bddda94a7f8a170305565416815b40", SVN: "17546" */ -const char *sysinfo_vcsrevision_scripts(void) { +const char *sysinfo_vcsrevision_scripts(void) +{ return sysinfo->p->vcsrevision_scripts; } @@ -934,7 +961,8 @@ const char *sysinfo_vcsrevision_scripts(void) { * Reloads the run-time (scripts) VCS revision information. To be used during * script reloads to refresh the cached version. */ -void sysinfo_vcsrevision_reload(void) { +void sysinfo_vcsrevision_reload(void) +{ if (sysinfo->p->vcsrevision_scripts != NULL) { aFree(sysinfo->p->vcsrevision_scripts); sysinfo->p->vcsrevision_scripts = NULL; @@ -956,7 +984,8 @@ void sysinfo_vcsrevision_reload(void) { * @retval false if the current process is running as regular user, or * in any case under Windows. */ -bool sysinfo_is_superuser(void) { +bool sysinfo_is_superuser(void) +{ #ifndef _WIN32 if (geteuid() == 0) return true; @@ -967,7 +996,8 @@ bool sysinfo_is_superuser(void) { /** * Interface runtime initialization. */ -void sysinfo_init(void) { +void sysinfo_init(void) +{ sysinfo->p->compiler = SYSINFO_COMPILER; #ifdef WIN32 sysinfo->p->platform = "Windows"; @@ -993,7 +1023,8 @@ void sysinfo_init(void) { /** * Interface shutdown cleanup. */ -void sysinfo_final(void) { +void sysinfo_final(void) +{ #ifdef WIN32 // Only need to be free'd in win32, they're #defined elsewhere if (sysinfo->p->osversion) @@ -1035,7 +1066,8 @@ static const char *sysinfo_time(void) /** * Interface default values initialization. */ -void sysinfo_defaults(void) { +void sysinfo_defaults(void) +{ sysinfo = &sysinfo_s; memset(&sysinfo_p, '\0', sizeof(sysinfo_p)); sysinfo->p = &sysinfo_p; diff --git a/src/common/utils.c b/src/common/utils.c index 73df3aae1..d393a6c23 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -54,6 +54,9 @@ void WriteDump(FILE* fp, const void* buffer, size_t length) size_t i; char hex[48+1], ascii[16+1]; + nullpo_retv(fp); + nullpo_retv(buffer); + fprintf(fp, "--- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F 0123456789ABCDEF\n"); ascii[16] = 0; @@ -78,10 +81,12 @@ void WriteDump(FILE* fp, const void* buffer, size_t length) } /// Dumps given buffer on the console. -void ShowDump(const void *buffer, size_t length) { +void ShowDump(const void *buffer, size_t length) +{ size_t i; char hex[48+1], ascii[16+1]; + nullpo_retv(buffer); ShowDebug("--- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F 0123456789ABCDEF\n"); ascii[16] = 0; @@ -108,6 +113,7 @@ static char* checkpath(char *path, const char *srcpath) { // just make sure the char*path is not const char *p = path; + if (NULL == path || NULL == srcpath) return path; while(*srcpath) { @@ -400,7 +406,9 @@ int apply_percentrate(int value, int rate, int maxrate) //----------------------------------------------------- const char* timestamp2string(char* str, size_t size, time_t timestamp, const char* format) { - size_t len = strftime(str, size, format, localtime(×tamp)); + size_t len; + nullpo_retr(NULL, str); + len = strftime(str, size, format, localtime(×tamp)); memset(str + len, '\0', size - len); return str; } @@ -413,6 +421,7 @@ bool HCache_check(const char *file) char s_path[255], dT[1]; time_t rtime; + nullpo_retr(false, file); if (!(first = fopen(file,"rb"))) return false; @@ -456,10 +465,14 @@ bool HCache_check(const char *file) return true; } -FILE *HCache_open(const char *file, const char *opt) { +FILE *HCache_open(const char *file, const char *opt) +{ FILE *first; char s_path[255]; + nullpo_retr(NULL, file); + nullpo_retr(NULL, opt); + if( file[0] == '.' && file[1] == '/' ) file += 2; else if( file[0] == '.' ) @@ -498,15 +511,19 @@ void HCache_init(void) } /* transit to fread, shields vs warn_unused_result */ -size_t hread(void * ptr, size_t size, size_t count, FILE * stream) { +size_t hread(void *ptr, size_t size, size_t count, FILE *stream) +{ return fread(ptr, size, count, stream); } + /* transit to fwrite, shields vs warn_unused_result */ -size_t hwrite(const void * ptr, size_t size, size_t count, FILE * stream) { +size_t hwrite(const void *ptr, size_t size, size_t count, FILE *stream) +{ return fwrite(ptr, size, count, stream); } -void HCache_defaults(void) { +void HCache_defaults(void) +{ HCache = &HCache_s; HCache->init = HCache_init; diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index af5ab99af..f801e4147 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -457,7 +457,7 @@ void itemdb2sql_tableheader(void) " `equip_jobs` bigint(20) UNSIGNED DEFAULT NULL,\n" " `equip_upper` tinyint(8) UNSIGNED DEFAULT NULL,\n" " `equip_genders` tinyint(2) UNSIGNED DEFAULT NULL,\n" - " `equip_locations` smallint(4) UNSIGNED DEFAULT NULL,\n" + " `equip_locations` mediumint(8) UNSIGNED DEFAULT NULL,\n" " `weapon_level` tinyint(2) UNSIGNED DEFAULT NULL,\n" " `equip_level_min` smallint(5) UNSIGNED DEFAULT NULL,\n" " `equip_level_max` smallint(5) UNSIGNED DEFAULT NULL,\n" |