diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/HPM.h | 4 | ||||
-rw-r--r-- | src/common/Makefile.in | 9 | ||||
-rw-r--r-- | src/common/cbasetypes.h | 26 | ||||
-rw-r--r-- | src/common/core.c | 3 | ||||
-rw-r--r-- | src/common/db.h | 6 | ||||
-rw-r--r-- | src/common/grfio.c | 23 | ||||
-rw-r--r-- | src/common/malloc.c | 2 | ||||
-rw-r--r-- | src/common/mmo.h | 3 | ||||
-rw-r--r-- | src/common/nullpo.c | 94 | ||||
-rw-r--r-- | src/common/nullpo.h | 302 | ||||
-rw-r--r-- | src/common/socket.c | 12 | ||||
-rw-r--r-- | src/common/sql.c | 4 | ||||
-rw-r--r-- | src/common/strlib.c | 19 | ||||
-rw-r--r-- | src/common/timer.c | 8 |
14 files changed, 179 insertions, 336 deletions
diff --git a/src/common/HPM.h b/src/common/HPM.h index 5466693ab..d5a5cbb6a 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -28,8 +28,10 @@ #define plugin_import(x,y,z) (z)dlsym((x),(y)) #define plugin_close(x) dlclose(x) - #ifdef CYGWIN + #if defined CYGWIN #define DLL_EXT ".dll" + #elif defined __DARWIN__ + #define DLL_EXT ".dylib" #else #define DLL_EXT ".so" #endif diff --git a/src/common/Makefile.in b/src/common/Makefile.in index 1e23ab5e8..7bb9ae630 100644 --- a/src/common/Makefile.in +++ b/src/common/Makefile.in @@ -15,8 +15,8 @@ MT19937AR_H = $(MT19937AR_D)/mt19937ar.h MT19937AR_INCLUDE = -I$(MT19937AR_D) COMMON_SHARED_C = conf.c db.c des.c ers.c grfio.c HPM.c mapindex.c md5calc.c \ - mempool.c mutex.c nullpo.c raconf.c random.c showmsg.c strlib.c \ - thread.c timer.c utils.c + mutex.c nullpo.c random.c showmsg.c strlib.c thread.c \ + timer.c utils.c COMMON_C = $(COMMON_SHARED_C) COMMON_SHARED_OBJ = $(patsubst %.c,%.o,$(COMMON_SHARED_C)) COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \ @@ -25,9 +25,8 @@ COMMON_MINI_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \ miniconsole.o minicore.o minimalloc.o minisocket.o) COMMON_C += console.c core.c malloc.c socket.c COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \ - evdp.h grfio.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h \ - mempool.h mmo.h mutex.h netbuffer.h network.h nullpo.h raconf.h \ - random.h showmsg.h socket.h spinlock.h sql.h strlib.h \ + grfio.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h mmo.h mutex.h \ + nullpo.h random.h showmsg.h socket.h spinlock.h sql.h strlib.h \ thread.h timer.h utils.h winapi.h COMMON_SQL_OBJ = obj_sql/sql.o diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 6de2ace01..120f4f861 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -255,6 +255,13 @@ typedef uintptr_t uintptr; #define ra_align(n) __attribute__(( aligned(n) )) #endif +// Directives for the (clang) static analyzer +#ifdef __clang__ +#define analyzer_noreturn __attribute__((analyzer_noreturn)) +#else +#define analyzer_noreturn +#endif + ///////////////////////////// // for those still not building c++ @@ -353,23 +360,6 @@ typedef char bool; #endif ////////////////////////////////////////////////////////////////////////// -// Assert - -#if ! defined(Assert) -#if defined(RELEASE) -#define Assert(EX) -#else -// extern "C" { -#include <assert.h> -// } -#if !defined(DEFCPP) && defined(WIN32) && !defined(MINGW) -#include <crtdbg.h> -#endif -#define Assert(EX) assert(EX) -#endif -#endif /* ! defined(Assert) */ - -////////////////////////////////////////////////////////////////////////// // Has to be unsigned to avoid problems in some systems // Problems arise when these functions expect an argument in the range [0,256[ and are fed a signed char. #include <ctype.h> @@ -405,7 +395,7 @@ typedef char bool; ////////////////////////////////////////////////////////////////////////// -// Use the preprocessor to 'stringify' stuff (concert to a string). +// Use the preprocessor to 'stringify' stuff (convert to a string). // example: // #define TESTE blabla // QUOTE(TESTE) -> "TESTE" diff --git a/src/common/core.c b/src/common/core.c index dd839b372..8178a48a5 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -15,7 +15,6 @@ #include "../common/socket.h" #include "../common/timer.h" #include "../common/thread.h" - #include "../common/mempool.h" #include "../common/sql.h" #include "../config/core.h" #include "../common/HPM.h" @@ -328,7 +327,6 @@ int main (int argc, char **argv) { Sql_Init(); rathread_init(); - mempool_init(); DB->init(); signals_init(); @@ -370,7 +368,6 @@ int main (int argc, char **argv) { timer->final(); socket_final(); DB->final(); - mempool_final(); rathread_final(); #endif diff --git a/src/common/db.h b/src/common/db.h index b9d6af382..5f4478909 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -1121,8 +1121,10 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...); #define VECTOR_ENSURE(__vec,__n,__step) \ do{ \ size_t _empty_ = VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec); \ - while( (__n) > _empty_ ) _empty_ += (__step); \ - if( _empty_ != VECTOR_CAPACITY(__vec)-VECTOR_LENGTH(__vec) ) VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \ + if( (__n) > _empty_ ) { \ + while( (__n) > _empty_ ) _empty_ += (__step); \ + VECTOR_RESIZE(__vec,_empty_+VECTOR_LENGTH(__vec)); \ + } \ }while(0) 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); diff --git a/src/common/malloc.c b/src/common/malloc.c index 1cb7836ab..23e28a65f 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -669,7 +669,7 @@ void memmgr_report (int extra) { struct { const char *file; unsigned short line; - unsigned int size; + size_t size; unsigned int count; } data[100]; memset(&data, 0, sizeof(data)); diff --git a/src/common/mmo.h b/src/common/mmo.h index 47257265f..b33b01fa7 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -284,7 +284,8 @@ struct accreg { // For saving status changes across sessions. [Skotlex] struct status_change_data { unsigned short type; //SC_type - long val1, val2, val3, val4, tick; //Remaining duration. + int val1, val2, val3, val4; + unsigned int tick; //Remaining duration. }; struct storage_data { diff --git a/src/common/nullpo.c b/src/common/nullpo.c index 4383109a7..20180dd3b 100644 --- a/src/common/nullpo.c +++ b/src/common/nullpo.c @@ -4,88 +4,26 @@ #include <stdio.h> #include <stdarg.h> #include <string.h> -#include "nullpo.h" +#include "../common/nullpo.h" #include "../common/showmsg.h" -// #include "logs.h" // 布石してみる -static void nullpo_info_core(const char *file, int line, const char *func, - const char *fmt, va_list ap); - -/*====================================== - * Nullチェック 及び 情報出力 - *--------------------------------------*/ -int nullpo_chk_f(const char *file, int line, const char *func, const void *target, - const char *fmt, ...) -{ - va_list ap; - - if (target != NULL) - return 0; - - va_start(ap, fmt); - nullpo_info_core(file, line, func, fmt, ap); - va_end(ap); - return 1; -} - -int nullpo_chk(const char *file, int line, const char *func, const void *target) -{ - if (target != NULL) - return 0; - - nullpo_info_core(file, line, func, NULL, NULL); - return 1; -} - - -/*====================================== - * nullpo情報出力(外部呼出し向けラッパ) - *--------------------------------------*/ -void nullpo_info_f(const char *file, int line, const char *func, - const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - nullpo_info_core(file, line, func, fmt, ap); - va_end(ap); -} - -void nullpo_info(const char *file, int line, const char *func) -{ - nullpo_info_core(file, line, func, NULL, NULL); -} - - -/*====================================== - * nullpo情報出力(Main) - *--------------------------------------*/ -static void nullpo_info_core(const char *file, int line, const char *func, - const char *fmt, va_list ap) -{ +/** + * Reports failed assertions or NULL pointers + * + * @param file Source file where the error was detected + * @param line Line + * @param func Function + * @param targetname Name of the checked symbol + * @param title Message title to display (i.e. failed assertion or nullpo info) + */ +void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title) { if (file == NULL) file = "??"; - func = - func == NULL ? "unknown": - func[0] == '\0' ? "unknown": - func; - - ShowMessage("--- nullpo info --------------------------------------------\n"); - ShowMessage("%s:%d: in func `%s'\n", file, line, func); - if (fmt != NULL) - { - if (fmt[0] != '\0') - { - vprintf(fmt, ap); - - // 最後に改行したか確認 - if (fmt[strlen(fmt)-1] != '\n') - ShowMessage("\n"); - } - } - ShowMessage("--- end nullpo info ----------------------------------------\n"); + if (func == NULL || *func == '\0') + func = "unknown"; - // ここらでnullpoログをファイルに書き出せたら - // まとめて提出できるなと思っていたり。 + ShowError("--- %s --------------------------------------------\n", title); + ShowError("%s:%d: '%s' in function `%s'\n", file, line, targetname, func); + ShowError("--- end %s ----------------------------------------\n", title); } diff --git a/src/common/nullpo.h b/src/common/nullpo.h index 8ee86a782..ae39b1151 100644 --- a/src/common/nullpo.h +++ b/src/common/nullpo.h @@ -1,225 +1,127 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#ifndef _NULLPO_H_ -#define _NULLPO_H_ - +#ifndef COMMON_NULLPO_H +#define COMMON_NULLPO_H #include "../common/cbasetypes.h" -#define NLP_MARK __FILE__, __LINE__, __func__ - // enabled by default on debug builds #if defined(DEBUG) && !defined(NULLPO_CHECK) #define NULLPO_CHECK #endif -/*---------------------------------------------------------------------------- - * Macros - *---------------------------------------------------------------------------- - */ -/*====================================== - * Nullチェック 及び 情報出力後 return - *・展開するとifとかreturn等が出るので - * 一行単体で使ってください。 - *・nullpo_ret(x = func()); - * のような使用法も想定しています。 - *-------------------------------------- - * nullpo_ret(t) - * 戻り値 0固定 - * [引数] - * t チェック対象 - *-------------------------------------- - * nullpo_retv(t) - * 戻り値 なし - * [引数] - * t チェック対象 - *-------------------------------------- - * nullpo_retr(ret, t) - * 戻り値 指定 - * [引数] - * ret return(ret); - * t チェック対象 - *-------------------------------------- - * nullpo_ret_f(t, fmt, ...) - * 詳細情報出力用 - * 戻り値 0 - * [引数] - * t チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- - * nullpo_retv_f(t, fmt, ...) - * 詳細情報出力用 - * 戻り値 なし - * [引数] - * t チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- - * nullpo_retr_f(ret, t, fmt, ...) - * 詳細情報出力用 - * 戻り値 指定 - * [引数] - * ret return(ret); - * t チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- - */ +// Skip assert checks on release builds +#if !defined(RELEASE) && !defined(ASSERT_CHECK) +#define ASSERT_CHECK +#endif + +/** Assert */ + +#if defined(ASSERT_CHECK) +// extern "C" { +#include <assert.h> +// } +#if !defined(DEFCPP) && defined(WIN32) && !defined(MINGW) +#include <crtdbg.h> +#endif // !DEFCPP && WIN && !MINGW +#define Assert(EX) assert(EX) +#define Assert_chk(EX) ( (EX) ? false : (assert_report(__FILE__, __LINE__, __func__, #EX, "failed assertion"), true) ) +#else // ! ASSERT_CHECK +#define Assert(EX) (EX) +#define Assert_chk(EX) ((EX), false) +#endif // ASSERT_CHECK #if defined(NULLPO_CHECK) +/** + * Reports NULL pointer information if the passed pointer is NULL + * + * @param t pointer to check + * @return true if the passed pointer is NULL, false otherwise + */ +#define nullpo_chk(t) ( (t) != NULL ? false : (assert_report(__FILE__, __LINE__, __func__, #t, "nullpo info"), true) ) +#else // ! NULLPO_CHECK +#define nullpo_chk(t) ((t), false) +#endif // NULLPO_CHECK + +/** + * The following macros check for NULL pointers and return from the current + * function or block in case one is found. + * + * It is guaranteed that the argument is evaluated once and only once, so it + * is safe to call them as: + * nullpo_ret(x = func()); + * The macros can be used safely in any context, as they expand to a do/while + * construct, except nullpo_retb, which expands to an if/else construct. + */ +/** + * Returns 0 if a NULL pointer is found. + * + * @param t pointer to check + */ #define nullpo_ret(t) \ - if (nullpo_chk(NLP_MARK, (void *)(t))) {return(0);} - -#define nullpo_retv(t) \ - if (nullpo_chk(NLP_MARK, (void *)(t))) {return;} - -#define nullpo_retr(ret, t) \ - if (nullpo_chk(NLP_MARK, (void *)(t))) {return(ret);} - -#define nullpo_retb(t) \ - if (nullpo_chk(NLP_MARK, (void *)(t))) {break;} - -// 可変引数マクロに関する条件コンパイル -#if __STDC_VERSION__ >= 199901L -/* C99に対応 */ -#define nullpo_ret_f(t, fmt, ...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(0);} - -#define nullpo_retv_f(t, fmt, ...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return;} - -#define nullpo_retr_f(ret, t, fmt, ...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {return(ret);} - -#define nullpo_retb_f(t, fmt, ...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), __VA_ARGS__)) {break;} + do { if (nullpo_chk(t)) return(0); } while(0) -#elif __GNUC__ >= 2 -/* GCC用 */ -#define nullpo_ret_f(t, fmt, args...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(0);} - -#define nullpo_retv_f(t, fmt, args...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return;} - -#define nullpo_retr_f(ret, t, fmt, args...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {return(ret);} - -#define nullpo_retb_f(t, fmt, args...) \ - if (nullpo_chk_f(NLP_MARK, (void *)(t), (fmt), ## args)) {break;} - -#else - -/* その他の場合・・・ orz */ - -#endif - -#else /* NULLPO_CHECK */ -/* No Nullpo check */ - -// if((t)){;} -// 良い方法が思いつかなかったので・・・苦肉の策です。 -// 一応ワーニングは出ないはず - -#define nullpo_ret(t) (void)(t) -#define nullpo_retv(t) (void)(t) -#define nullpo_retr(ret, t) (void)(t) -#define nullpo_retb(t) (void)(t) - -// 可変引数マクロに関する条件コンパイル -#if __STDC_VERSION__ >= 199901L -/* C99に対応 */ -#define nullpo_ret_f(t, fmt, ...) (void)(t) -#define nullpo_retv_f(t, fmt, ...) (void)(t) -#define nullpo_retr_f(ret, t, fmt, ...) (void)(t) -#define nullpo_retb_f(t, fmt, ...) (void)(t) - -#elif __GNUC__ >= 2 -/* GCC用 */ -#define nullpo_ret_f(t, fmt, args...) (void)(t) -#define nullpo_retv_f(t, fmt, args...) (void)(t) -#define nullpo_retr_f(ret, t, fmt, args...) (void)(t) -#define nullpo_retb_f(t, fmt, args...) (void)(t) - -#else -/* その他の場合・・・ orz */ -#endif +/** + * Returns 0 if the given assertion fails. + * + * @param t statement to check + */ +#define Assert_ret(t) \ + do { if (Assert_chk(t)) return(0); } while(0) -#endif /* NULLPO_CHECK */ +/** + * Returns void if a NULL pointer is found. + * + * @param t pointer to check + */ +#define nullpo_retv(t) \ + do { if (nullpo_chk(t)) return; } while(0) -/*---------------------------------------------------------------------------- - * Functions - *---------------------------------------------------------------------------- +/** + * Returns void if the given assertion fails. + * + * @param t statement to check */ -/*====================================== - * nullpo_chk - * Nullチェック 及び 情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * target チェック対象 - * [返り値] - * 0 OK - * 1 NULL - *-------------------------------------- +#define Assert_retv(t) \ + do { if (Assert_chk(t)) return; } while(0) + +/** + * Returns the given value if a NULL pointer is found. + * + * @param ret value to return + * @param t pointer to check */ -int nullpo_chk(const char *file, int line, const char *func, const void *target); - - -/*====================================== - * nullpo_chk_f - * Nullチェック 及び 詳細な情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * target チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - * [返り値] - * 0 OK - * 1 NULL - *-------------------------------------- +#define nullpo_retr(ret, t) \ + do { if (nullpo_chk(t)) return(ret); } while(0) + +/** + * Returns the given value if the given assertion fails. + * + * @param ret value to return + * @param t statement to check */ -int nullpo_chk_f(const char *file, int line, const char *func, const void *target, - const char *fmt, ...) - __attribute__((format(printf,5,6))); - - -/*====================================== - * nullpo_info - * nullpo情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - *-------------------------------------- +#define Assert_retr(ret, t) \ + do { if (Assert_chk(t)) return(ret); } while(0) + +/** + * Breaks from the current loop/switch if a NULL pointer is found. + * + * @param t pointer to check */ -void nullpo_info(const char *file, int line, const char *func); - - -/*====================================== - * nullpo_info_f - * nullpo詳細情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- +#define nullpo_retb(t) \ + if (nullpo_chk(t)) break; else (void)0 + +/** + * Breaks from the current loop/switch if the given assertion fails. + * + * @param t statement to check */ -void nullpo_info_f(const char *file, int line, const char *func, - const char *fmt, ...) - __attribute__((format(printf,4,5))); +#define Assert_retb(t) \ + if (Assert_chk(t)) break; else (void)0 + +void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title); -#endif /* _NULLPO_H_ */ +#endif /* COMMON_NULLPO_H */ diff --git a/src/common/socket.c b/src/common/socket.c index 2ae9d44b3..9c6938008 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -340,7 +340,7 @@ void set_eof(int fd) int recv_to_fifo(int fd) { - int len; + ssize_t len; if( !session_isActive(fd) ) return -1; @@ -377,7 +377,7 @@ int recv_to_fifo(int fd) int send_from_fifo(int fd) { - int len; + ssize_t len; if( !session_isValid(fd) ) return -1; @@ -855,6 +855,10 @@ int do_sockets(int next) } } +#ifdef __clang_analyzer__ + // Let Clang's static analyzer know this never happens (it thinks it might because of a NULL check in session_isValid) + if (!session[i]) continue; +#endif // __clang_analyzer__ session[i]->func_parse(i); if(!session[i]) @@ -1330,7 +1334,7 @@ int socket_getips(uint32* ips, int max) void socket_init(void) { char *SOCKET_CONF_FILENAME = "conf/packet.conf"; - unsigned int rlim_cur = FD_SETSIZE; + uint64 rlim_cur = FD_SETSIZE; #ifdef WIN32 {// Start up windows networking @@ -1403,7 +1407,7 @@ void socket_init(void) timer->add_interval(timer->gettick()+1000, connect_check_clear, 0, 0, 5*60*1000); #endif - ShowInfo("Server supports up to '"CL_WHITE"%u"CL_RESET"' concurrent connections.\n", rlim_cur); + ShowInfo("Server supports up to '"CL_WHITE"%lld"CL_RESET"' concurrent connections.\n", rlim_cur); /* Hercules Plugin Manager */ HPM->share(session,"session"); diff --git a/src/common/sql.c b/src/common/sql.c index 0e06d6d18..79ccc8e92 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -1036,7 +1036,7 @@ void Sql_HerculesUpdateCheck(Sql* self) { fseek (ufp,1,SEEK_SET);/* woo. skip the # */ if( fgets(timestamp,sizeof(timestamp),ufp) ) { - unsigned int timestampui = atol(timestamp); + unsigned int timestampui = (unsigned int)atol(timestamp); if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) Sql_ShowDebug(self); if( Sql_NumRows(self) != 1 ) { @@ -1079,7 +1079,7 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename) { fseek (ifp,1,SEEK_SET);/* woo. skip the # */ if( fgets(timestamp,sizeof(timestamp),ifp) ) { - unsigned int timestampui = atol(timestamp); + unsigned int timestampui = (unsigned int)atol(timestamp); if( SQL_ERROR == SQL->Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) ) Sql_ShowDebug(self); else if( Sql_NumRows(self) == 1 ) { diff --git a/src/common/strlib.c b/src/common/strlib.c index e45cb0789..0f68eb206 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -952,7 +952,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r') continue; - columns = sv_split(line, strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); + columns = sv_split(line, (int)strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF)); if( columns < mincols ) { ShowError("sv_readdb: Insufficient columns in line %d of \"%s\" (found %d, need at least %d).\n", lines, path, columns, mincols); @@ -1018,7 +1018,8 @@ int StringBuf_Printf(StringBuf* self, const char* fmt, ...) { /// Appends the result of vprintf to the StringBuf int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) { - int n, size, off; + int n, off; + size_t size; for(;;) { va_list apcopy; @@ -1028,7 +1029,7 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) { n = vsnprintf(self->ptr_, size, fmt, apcopy); va_end(apcopy); /* If that worked, return the length. */ - if( n > -1 && n < size ) { + if( n > -1 && (size_t)n < size ) { self->ptr_ += n; return (int)(self->ptr_ - self->buf_); } @@ -1042,11 +1043,11 @@ int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap) { /// Appends the contents of another StringBuf to the StringBuf int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) { - int available = self->max_ - (self->ptr_ - self->buf_); - int needed = (int)(sbuf->ptr_ - sbuf->buf_); + size_t available = self->max_ - (self->ptr_ - self->buf_); + size_t needed = sbuf->ptr_ - sbuf->buf_; if( needed >= available ) { - int off = (int)(self->ptr_ - self->buf_); + size_t off = (self->ptr_ - self->buf_); self->max_ += needed; self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1); self->ptr_ = self->buf_ + off; @@ -1059,12 +1060,12 @@ int StringBuf_Append(StringBuf* self, const StringBuf* sbuf) { // Appends str to the StringBuf int StringBuf_AppendStr(StringBuf* self, const char* str) { - int available = self->max_ - (self->ptr_ - self->buf_); - int needed = (int)strlen(str); + size_t available = self->max_ - (self->ptr_ - self->buf_); + size_t needed = strlen(str); if( needed >= available ) { // not enough space, expand the buffer (minimum expansion = 1024) - int off = (int)(self->ptr_ - self->buf_); + size_t off = (self->ptr_ - self->buf_); self->max_ += max(needed, 1024); self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1); self->ptr_ = self->buf_ + off; diff --git a/src/common/timer.c b/src/common/timer.c index e5cf5df2a..7f9e20dad 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -142,7 +142,7 @@ static void rdtsc_calibrate(){ * platform-abstracted tick retrieval * @return server's current tick */ -static int64 tick(void) { +static int64 sys_tick(void) { #if defined(WIN32) // Windows: GetTickCount/GetTickCount64: Return the number of // milliseconds that have elapsed since the system was started. @@ -206,7 +206,7 @@ static int gettick_count = 1; int64 timer_gettick_nocache(void) { gettick_count = TICK_CACHE; - gettick_cache = tick(); + gettick_cache = sys_tick(); return gettick_cache; } @@ -219,11 +219,11 @@ int64 timer_gettick(void) { // tick doesn't get cached int64 timer_gettick_nocache(void) { - return tick(); + return sys_tick(); } int64 timer_gettick(void) { - return tick(); + return sys_tick(); } ////////////////////////////////////////////////////////////////////////// #endif |