From efe4174e59dc462130fde872365e891a7c73654a Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 10 Dec 2013 20:47:51 +0100 Subject: Changed plugin extension from .so to .dylib on OS X - No functional changes. That's just the correct OS X file extension for dynamic libs. Signed-off-by: Haru --- src/common/HPM.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') 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 -- cgit v1.2.3-70-g09d2 From 853c5a3141d1f431af95aed55d991334a2b995f6 Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 13 Dec 2013 16:28:22 +0100 Subject: Nullpo cleanup - Removed unused, nonportable nullpo checks with formatted message (related: eAthena r15245) - Converted nullpo_chk to a macro, to make it easier on the llvm static analyzer. - Added more details to the nullpo_info reports (related: eAthena r15246) - Ensured that the nullpo check macros evaluate their pointer argument once and only once, so that it's safe to use with expressions that assign values or have side-effects. Signed-off-by: Haru --- src/common/nullpo.c | 82 ++--------------- src/common/nullpo.h | 253 ++++++++++++---------------------------------------- src/map/battle.c | 22 ++--- 3 files changed, 72 insertions(+), 285 deletions(-) (limited to 'src') diff --git a/src/common/nullpo.c b/src/common/nullpo.c index 4383109a7..f0fc2c7ab 100644 --- a/src/common/nullpo.c +++ b/src/common/nullpo.c @@ -6,86 +6,18 @@ #include #include "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 NULL pointer information + */ +void nullpo_info(const char *file, int line, const char *func, const char *targetname) { if (file == NULL) file = "??"; - func = - func == NULL ? "unknown": - func[0] == '\0' ? "unknown": - func; + if (func == NULL || *func == '\0') + func = "unknown"; 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("%s:%d: target '%s' in func `%s'\n", file, line, targetname, func); ShowMessage("--- end nullpo info ----------------------------------------\n"); - - // ここらでnullpoログをファイルに書き出せたら - // まとめて提出できるなと思っていたり。 } diff --git a/src/common/nullpo.h b/src/common/nullpo.h index 8ee86a782..5400acaa1 100644 --- a/src/common/nullpo.h +++ b/src/common/nullpo.h @@ -14,212 +14,73 @@ #define NULLPO_CHECK #endif -/*---------------------------------------------------------------------------- - * Macros - *---------------------------------------------------------------------------- +#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 */ -/*====================================== - * 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に渡される - * 備考や関係変数の書き出しなどに - *-------------------------------------- +#define nullpo_chk(t) ( (t) != NULL ? false : (nullpo_info(NLP_MARK, #t), 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. */ -#if defined(NULLPO_CHECK) - +/** + * 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;} - -#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 */ + do { if (nullpo_chk(t)) return(0); } while(0) -#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 - -#endif /* NULLPO_CHECK */ - -/*---------------------------------------------------------------------------- - * Functions - *---------------------------------------------------------------------------- +/** + * Returns void if a NULL pointer is found. + * + * @param t pointer to check */ -/*====================================== - * nullpo_chk - * Nullチェック 及び 情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * target チェック対象 - * [返り値] - * 0 OK - * 1 NULL - *-------------------------------------- - */ -int nullpo_chk(const char *file, int line, const char *func, const void *target); - +#define nullpo_retv(t) \ + do { if (nullpo_chk(t)) return; } while(0) -/*====================================== - * nullpo_chk_f - * Nullチェック 及び 詳細な情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - * target チェック対象 - * fmt ... vprintfに渡される - * 備考や関係変数の書き出しなどに - * [返り値] - * 0 OK - * 1 NULL - *-------------------------------------- +/** + * Returns the given value if a NULL pointer is found. + * + * @param ret value to return + * @param t pointer 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))); - +#define nullpo_retr(ret, t) \ + do { if (nullpo_chk(t)) return(ret); } while(0) -/*====================================== - * nullpo_info - * nullpo情報出力 - * [引数] - * file __FILE__ - * line __LINE__ - * func __func__ (関数名) - * これらには NLP_MARK を使うとよい - *-------------------------------------- +/** + * Breaks fromt he 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 + +/** + * Reports NULL pointer information + * + * @param file Source file where the error was detected + * @param line Line + * @param func Function + * @param targetname Name of the checked symbol + * + * It is possible to use the NLP_MARK macro that expands to: + * __FILE__, __LINE__, __func__ */ -void nullpo_info_f(const char *file, int line, const char *func, - const char *fmt, ...) - __attribute__((format(printf,4,5))); - +void nullpo_info(const char *file, int line, const char *func, const char *targetname); #endif /* _NULLPO_H_ */ diff --git a/src/map/battle.c b/src/map/battle.c index b3e7e6dc2..94c8fe581 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -3209,11 +3209,9 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list memset(&ad,0,sizeof(ad)); memset(&flag,0,sizeof(flag)); - if(src==NULL || target==NULL) - { - nullpo_info(NLP_MARK); - return ad; - } + nullpo_retr(ad, src); + nullpo_retr(ad, target); + //Initial Values ad.damage = 1; ad.div_=skill->get_num(skill_id,skill_lv); @@ -3521,10 +3519,8 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * memset(&md,0,sizeof(md)); - if( src == NULL || target == NULL ){ - nullpo_info(NLP_MARK); - return md; - } + nullpo_retr(md, src); + nullpo_retr(md, target); //Some initial values md.amotion=skill->get_inf(skill_id)&INF_GROUND_SKILL?0:sstatus->amotion; @@ -3947,11 +3943,9 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list memset(&wd,0,sizeof(wd)); memset(&flag,0,sizeof(flag)); - if(src==NULL || target==NULL) - { - nullpo_info(NLP_MARK); - return wd; - } + nullpo_retr(wd, src); + nullpo_retr(wd, target); + //Initial flag flag.rh=1; flag.weapon=1; -- cgit v1.2.3-70-g09d2 From a23d072a66d2569ba13921522be3c82ae9aad576 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 14 Dec 2013 15:14:23 +0100 Subject: Added support for non-aborting assertions - Added Assert_ret, Assert_retv, Assert_retb, Assert_retr, working similarly to the corresponding nullpo_ functions. - Moved Assert-related macros to nullpo.h, since they share some functions. Signed-off-by: Haru --- src/common/cbasetypes.h | 19 +------------ src/common/nullpo.c | 18 ++++++++---- src/common/nullpo.h | 75 ++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 71 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 6de2ace01..d00f49864 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -352,23 +352,6 @@ typedef char bool; #define PATHSEP_STR "/" #endif -////////////////////////////////////////////////////////////////////////// -// Assert - -#if ! defined(Assert) -#if defined(RELEASE) -#define Assert(EX) -#else -// extern "C" { -#include -// } -#if !defined(DEFCPP) && defined(WIN32) && !defined(MINGW) -#include -#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. @@ -405,7 +388,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/nullpo.c b/src/common/nullpo.c index f0fc2c7ab..20180dd3b 100644 --- a/src/common/nullpo.c +++ b/src/common/nullpo.c @@ -4,20 +4,26 @@ #include #include #include -#include "nullpo.h" +#include "../common/nullpo.h" #include "../common/showmsg.h" /** - * Reports NULL pointer information + * 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 nullpo_info(const char *file, int line, const char *func, const char *targetname) { +void assert_report(const char *file, int line, const char *func, const char *targetname, const char *title) { if (file == NULL) file = "??"; if (func == NULL || *func == '\0') func = "unknown"; - ShowMessage("--- nullpo info --------------------------------------------\n"); - ShowMessage("%s:%d: target '%s' in func `%s'\n", file, line, targetname, func); - ShowMessage("--- end nullpo info ----------------------------------------\n"); + 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 5400acaa1..ae39b1151 100644 --- a/src/common/nullpo.h +++ b/src/common/nullpo.h @@ -1,19 +1,37 @@ // 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 +// Skip assert checks on release builds +#if !defined(RELEASE) && !defined(ASSERT_CHECK) +#define ASSERT_CHECK +#endif + +/** Assert */ + +#if defined(ASSERT_CHECK) +// extern "C" { +#include +// } +#if !defined(DEFCPP) && defined(WIN32) && !defined(MINGW) +#include +#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 @@ -21,7 +39,7 @@ * @param t pointer to check * @return true if the passed pointer is NULL, false otherwise */ -#define nullpo_chk(t) ( (t) != NULL ? false : (nullpo_info(NLP_MARK, #t), true) ) +#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 @@ -45,6 +63,14 @@ #define nullpo_ret(t) \ do { if (nullpo_chk(t)) return(0); } while(0) +/** + * 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) + /** * Returns void if a NULL pointer is found. * @@ -53,6 +79,14 @@ #define nullpo_retv(t) \ do { if (nullpo_chk(t)) return; } while(0) +/** + * Returns void if the given assertion fails. + * + * @param t statement to check + */ +#define Assert_retv(t) \ + do { if (Assert_chk(t)) return; } while(0) + /** * Returns the given value if a NULL pointer is found. * @@ -63,7 +97,16 @@ do { if (nullpo_chk(t)) return(ret); } while(0) /** - * Breaks fromt he current loop/switch if a NULL pointer is found. + * Returns the given value if the given assertion fails. + * + * @param ret value to return + * @param t statement to check + */ +#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 */ @@ -71,16 +114,14 @@ if (nullpo_chk(t)) break; else (void)0 /** - * Reports NULL pointer information - * - * @param file Source file where the error was detected - * @param line Line - * @param func Function - * @param targetname Name of the checked symbol + * Breaks from the current loop/switch if the given assertion fails. * - * It is possible to use the NLP_MARK macro that expands to: - * __FILE__, __LINE__, __func__ + * @param t statement to check */ -void nullpo_info(const char *file, int line, const char *func, const char *targetname); +#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 */ -- cgit v1.2.3-70-g09d2 From 15a0f6dea6f4f3c5adc9a1bc9e7e8be81cc49c48 Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 10 Dec 2013 19:48:55 +0100 Subject: Fixed several compiler warnings - Warnings detected thanks to Xcode's compiler settings (more strict by default) and clang, warnings mostly but not only related to data sizes on 64 bit systems, that were silenced until now by very lax compiler settings. - This also decreases by a great deal the amount of warnings produced by MSVC in x64 mode (for the adventurous ones who tried that) - Also fixed (or silenced in case of false positives) the potential issues pointed out by the (awesome) clang static analyzer. - Patch co-produced with Ind, I'm merging and committing in his place! Signed-off-by: Haru --- 3rdparty/libconfig/extra/gen/Makefile | 1 + 3rdparty/libconfig/extra/gen/Makefile.in | 1 + 3rdparty/libconfig/extra/gen/clangwarnings.patch | 36 ++ 3rdparty/libconfig/extra/gen/scanner.l | 12 +- 3rdparty/libconfig/grammar.c | 4 +- 3rdparty/libconfig/scanctx.c | 2 + 3rdparty/libconfig/scanner.c | 117 ++--- 3rdparty/libconfig/scanner.h | 2 +- Hercules.xcodeproj/project.pbxproj | 2 + src/char/char.c | 57 ++- src/char/int_guild.c | 30 +- src/char/int_quest.c | 1 + src/char/inter.c | 2 +- src/common/Makefile.in | 9 +- src/common/cbasetypes.h | 7 + src/common/core.c | 3 - src/common/db.h | 6 +- src/common/grfio.c | 23 +- src/common/malloc.c | 2 +- src/common/mmo.h | 3 +- src/common/socket.c | 12 +- src/common/sql.c | 4 +- src/common/strlib.c | 19 +- src/config/renewal.h | 1 + src/login/account_sql.c | 7 +- src/login/login.c | 10 +- src/login/login.h | 4 +- src/map/atcommand.c | 52 +- src/map/battle.c | 28 +- src/map/clif.c | 95 ++-- src/map/clif.h | 24 +- src/map/guild.c | 14 +- src/map/homunculus.c | 2 +- src/map/intif.c | 10 +- src/map/intif.h | 8 +- src/map/irc-bot.c | 7 +- src/map/irc-bot.h | 2 +- src/map/itemdb.c | 9 +- src/map/map.c | 16 +- src/map/mob.c | 19 +- src/map/mob.h | 2 +- src/map/npc.c | 21 +- src/map/party.h | 10 +- src/map/path.c | 2 + src/map/pc.c | 19 +- src/map/pc_groups.c | 28 +- src/map/script.c | 56 +-- src/map/script.h | 5 +- src/map/skill.c | 589 +++++++++++++---------- src/map/status.c | 90 ++-- src/map/status.h | 15 + src/map/unit.c | 12 +- src/tool/Makefile.in | 4 +- src/tool/mapcache.c | 2 +- vcproj-10/mapcache.vcxproj | 8 +- vcproj-10/mapcache.vcxproj.filters | 6 + vcproj-11/mapcache.vcxproj | 6 +- vcproj-11/mapcache.vcxproj.filters | 10 +- vcproj-12/mapcache.vcxproj | 2 + vcproj-12/mapcache.vcxproj.filters | 10 +- vcproj-9/mapcache.vcproj | 8 + 61 files changed, 878 insertions(+), 690 deletions(-) create mode 100644 3rdparty/libconfig/extra/gen/clangwarnings.patch (limited to 'src') diff --git a/3rdparty/libconfig/extra/gen/Makefile b/3rdparty/libconfig/extra/gen/Makefile index b4d2db841..0b2e0655e 100644 --- a/3rdparty/libconfig/extra/gen/Makefile +++ b/3rdparty/libconfig/extra/gen/Makefile @@ -31,6 +31,7 @@ AM_YFLAGS = -d -p $(PARSER_PREFIX) AM_LFLAGS = --nounistd --header-file=scanner.h --prefix=$(PARSER_PREFIX) all: $(BUILT_SOURCES) + @patch -p1 < clangwarnings.patch .SUFFIXES: .c .l .y diff --git a/3rdparty/libconfig/extra/gen/Makefile.in b/3rdparty/libconfig/extra/gen/Makefile.in index 5850c2392..0bd4efd62 100644 --- a/3rdparty/libconfig/extra/gen/Makefile.in +++ b/3rdparty/libconfig/extra/gen/Makefile.in @@ -31,6 +31,7 @@ AM_YFLAGS = -d -p $(PARSER_PREFIX) AM_LFLAGS = --nounistd --header-file=scanner.h --prefix=$(PARSER_PREFIX) all: $(BUILT_SOURCES) + @patch -p1 < clangwarnings.patch .SUFFIXES: .c .l .y diff --git a/3rdparty/libconfig/extra/gen/clangwarnings.patch b/3rdparty/libconfig/extra/gen/clangwarnings.patch new file mode 100644 index 000000000..65aef9a08 --- /dev/null +++ b/3rdparty/libconfig/extra/gen/clangwarnings.patch @@ -0,0 +1,36 @@ +diff --git a/grammar.c b/grammar.c +index 3595578..26444f8 100644 +--- a/grammar.c ++++ b/grammar.c +@@ -1187,9 +1187,7 @@ void libconfig_yyerror(void *scanner, struct parse_context *ctx, + YYUSE (ctx); + YYUSE (scan_ctx); + +- if (!yymsg) +- yymsg = "Deleting"; +- YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); ++ YY_SYMBOL_PRINT (yymsg ? yymsg : "Deleting", yytype, yyvaluep, yylocationp); + + switch (yytype) + { +diff --git a/scanner.c b/scanner.c +index aebd34c..c3a717f 100644 +--- a/scanner.c ++++ b/scanner.c +@@ -1500,6 +1500,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner) + else + ret_val = EOB_ACT_CONTINUE_SCAN; + ++#ifndef __clang_analyzer__ ++ // FIXME: Clang's static analyzer complains about leaking the result of libconfig_yyrealloc + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); +@@ -1507,6 +1509,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } ++#endif // __clang_analyzer__ + + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; diff --git a/3rdparty/libconfig/extra/gen/scanner.l b/3rdparty/libconfig/extra/gen/scanner.l index 4b3048fab..66364e019 100644 --- a/3rdparty/libconfig/extra/gen/scanner.l +++ b/3rdparty/libconfig/extra/gen/scanner.l @@ -86,6 +86,13 @@ static unsigned long long fromhex(const char *s) #endif /* __MINGW32__ */ } +static int fromihex(const char *s) { + unsigned long l = strtoul(s, NULL, 16); + if (l > INT32_MAX) + l = INT32_MAX; + return (int)l; +} + %} true [Tt][Rr][Uu][Ee] @@ -178,10 +185,7 @@ include_open ^[ \t]*@include[ \t]+\" {float} { yylval->fval = atof(yytext); return(TOK_FLOAT); } {integer} { yylval->ival = atoi(yytext); return(TOK_INTEGER); } {integer64} { yylval->llval = atoll(yytext); return(TOK_INTEGER64); } -{hex} { - yylval->ival = strtoul(yytext, NULL, 16); - return(TOK_HEX); - } +{hex} { yylval->ival = fromihex(yytext); return(TOK_HEX); } {hex64} { yylval->llval = fromhex(yytext); return(TOK_HEX64); } \[ { return(TOK_ARRAY_START); } \] { return(TOK_ARRAY_END); } diff --git a/3rdparty/libconfig/grammar.c b/3rdparty/libconfig/grammar.c index 3595578de..26444f816 100644 --- a/3rdparty/libconfig/grammar.c +++ b/3rdparty/libconfig/grammar.c @@ -1187,9 +1187,7 @@ yydestruct (yymsg, yytype, yyvaluep, scanner, ctx, scan_ctx) YYUSE (ctx); YYUSE (scan_ctx); - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg ? yymsg : "Deleting", yytype, yyvaluep, yylocationp); switch (yytype) { diff --git a/3rdparty/libconfig/scanctx.c b/3rdparty/libconfig/scanctx.c index 7d7f4994c..e057d50bc 100644 --- a/3rdparty/libconfig/scanctx.c +++ b/3rdparty/libconfig/scanctx.c @@ -39,6 +39,7 @@ static const char *err_include_too_deep = "include file nesting too deep"; static const char *__scanctx_add_filename(struct scan_context *ctx, const char *filename) { +#ifndef __clang_analyzer__ // FIXME: Clang's static analyzer doesn't like this unsigned int count = ctx->num_filenames; const char **f; @@ -60,6 +61,7 @@ static const char *__scanctx_add_filename(struct scan_context *ctx, ctx->filenames[ctx->num_filenames] = filename; ++ctx->num_filenames; +#endif // __clang_analyzer__ return(filename); } diff --git a/3rdparty/libconfig/scanner.c b/3rdparty/libconfig/scanner.c index 6de72c2fd..c3a717ff0 100644 --- a/3rdparty/libconfig/scanner.c +++ b/3rdparty/libconfig/scanner.c @@ -625,8 +625,15 @@ static unsigned long long fromhex(const char *s) #endif /* __MINGW32__ */ } +static int fromihex(const char *s) { + unsigned long l = strtoul(s, NULL, 16); + if (l > INT32_MAX) + l = INT32_MAX; + return (int)l; +} + -#line 630 "scanner.c" +#line 637 "scanner.c" #define INITIAL 0 #define COMMENT 1 @@ -858,10 +865,10 @@ YY_DECL register int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 105 "scanner.l" +#line 112 "scanner.l" -#line 865 "scanner.c" +#line 872 "scanner.c" yylval = yylval_param; @@ -957,69 +964,69 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 107 "scanner.l" +#line 114 "scanner.l" { BEGIN COMMENT; } YY_BREAK case 2: YY_RULE_SETUP -#line 108 "scanner.l" +#line 115 "scanner.l" { BEGIN INITIAL; } YY_BREAK case 3: YY_RULE_SETUP -#line 109 "scanner.l" +#line 116 "scanner.l" { /* ignore */ } YY_BREAK case 4: /* rule 4 can match eol */ YY_RULE_SETUP -#line 110 "scanner.l" +#line 117 "scanner.l" { /* ignore */ } YY_BREAK case 5: YY_RULE_SETUP -#line 112 "scanner.l" +#line 119 "scanner.l" { BEGIN STRING; } YY_BREAK case 6: /* rule 6 can match eol */ YY_RULE_SETUP -#line 113 "scanner.l" +#line 120 "scanner.l" { scanctx_append_string(yyextra, yytext); } YY_BREAK case 7: YY_RULE_SETUP -#line 114 "scanner.l" +#line 121 "scanner.l" { scanctx_append_string(yyextra, "\n"); } YY_BREAK case 8: YY_RULE_SETUP -#line 115 "scanner.l" +#line 122 "scanner.l" { scanctx_append_string(yyextra, "\r"); } YY_BREAK case 9: YY_RULE_SETUP -#line 116 "scanner.l" +#line 123 "scanner.l" { scanctx_append_string(yyextra, "\t"); } YY_BREAK case 10: YY_RULE_SETUP -#line 117 "scanner.l" +#line 124 "scanner.l" { scanctx_append_string(yyextra, "\f"); } YY_BREAK case 11: YY_RULE_SETUP -#line 118 "scanner.l" +#line 125 "scanner.l" { scanctx_append_string(yyextra, "\\"); } YY_BREAK case 12: YY_RULE_SETUP -#line 119 "scanner.l" +#line 126 "scanner.l" { scanctx_append_string(yyextra, "\""); } YY_BREAK case 13: YY_RULE_SETUP -#line 120 "scanner.l" +#line 127 "scanner.l" { char c[2] = { (char)(strtol(yytext + 2, NULL, 16) & 0xFF), 0 }; @@ -1028,12 +1035,12 @@ YY_RULE_SETUP YY_BREAK case 14: YY_RULE_SETUP -#line 125 "scanner.l" +#line 132 "scanner.l" { scanctx_append_string(yyextra, "\\"); } YY_BREAK case 15: YY_RULE_SETUP -#line 126 "scanner.l" +#line 133 "scanner.l" { yylval->sval = scanctx_take_string(yyextra); BEGIN INITIAL; @@ -1042,18 +1049,18 @@ YY_RULE_SETUP YY_BREAK case 16: YY_RULE_SETUP -#line 132 "scanner.l" +#line 139 "scanner.l" { BEGIN SCRIPTBLOCK; } YY_BREAK case 17: /* rule 17 can match eol */ YY_RULE_SETUP -#line 133 "scanner.l" +#line 140 "scanner.l" { scanctx_append_string(yyextra, yytext); } YY_BREAK case 18: YY_RULE_SETUP -#line 134 "scanner.l" +#line 141 "scanner.l" { yylval->sval = scanctx_take_string(yyextra); BEGIN INITIAL; @@ -1062,28 +1069,28 @@ YY_RULE_SETUP YY_BREAK case 19: YY_RULE_SETUP -#line 140 "scanner.l" +#line 147 "scanner.l" { BEGIN INCLUDE; } YY_BREAK case 20: /* rule 20 can match eol */ YY_RULE_SETUP -#line 141 "scanner.l" +#line 148 "scanner.l" { scanctx_append_string(yyextra, yytext); } YY_BREAK case 21: YY_RULE_SETUP -#line 142 "scanner.l" +#line 149 "scanner.l" { scanctx_append_string(yyextra, "\\"); } YY_BREAK case 22: YY_RULE_SETUP -#line 143 "scanner.l" +#line 150 "scanner.l" { scanctx_append_string(yyextra, "\""); } YY_BREAK case 23: YY_RULE_SETUP -#line 144 "scanner.l" +#line 151 "scanner.l" { const char *error; FILE *fp = scanctx_push_include(yyextra, @@ -1109,100 +1116,97 @@ YY_RULE_SETUP case 24: /* rule 24 can match eol */ YY_RULE_SETUP -#line 168 "scanner.l" +#line 175 "scanner.l" { /* ignore */ } YY_BREAK case 25: YY_RULE_SETUP -#line 169 "scanner.l" +#line 176 "scanner.l" { /* ignore */ } YY_BREAK case 26: YY_RULE_SETUP -#line 171 "scanner.l" +#line 178 "scanner.l" { return(TOK_EQUALS); } YY_BREAK case 27: YY_RULE_SETUP -#line 172 "scanner.l" +#line 179 "scanner.l" { return(TOK_COMMA); } YY_BREAK case 28: YY_RULE_SETUP -#line 173 "scanner.l" +#line 180 "scanner.l" { return(TOK_GROUP_START); } YY_BREAK case 29: YY_RULE_SETUP -#line 174 "scanner.l" +#line 181 "scanner.l" { return(TOK_GROUP_END); } YY_BREAK case 30: YY_RULE_SETUP -#line 175 "scanner.l" +#line 182 "scanner.l" { yylval->ival = 1; return(TOK_BOOLEAN); } YY_BREAK case 31: YY_RULE_SETUP -#line 176 "scanner.l" +#line 183 "scanner.l" { yylval->ival = 0; return(TOK_BOOLEAN); } YY_BREAK case 32: YY_RULE_SETUP -#line 177 "scanner.l" +#line 184 "scanner.l" { yylval->sval = yytext; return(TOK_NAME); } YY_BREAK case 33: YY_RULE_SETUP -#line 178 "scanner.l" +#line 185 "scanner.l" { yylval->fval = atof(yytext); return(TOK_FLOAT); } YY_BREAK case 34: YY_RULE_SETUP -#line 179 "scanner.l" +#line 186 "scanner.l" { yylval->ival = atoi(yytext); return(TOK_INTEGER); } YY_BREAK case 35: YY_RULE_SETUP -#line 180 "scanner.l" +#line 187 "scanner.l" { yylval->llval = atoll(yytext); return(TOK_INTEGER64); } YY_BREAK case 36: YY_RULE_SETUP -#line 181 "scanner.l" -{ - yylval->ival = strtoul(yytext, NULL, 16); - return(TOK_HEX); - } +#line 188 "scanner.l" +{ yylval->ival = fromihex(yytext); return(TOK_HEX); } YY_BREAK case 37: YY_RULE_SETUP -#line 185 "scanner.l" +#line 189 "scanner.l" { yylval->llval = fromhex(yytext); return(TOK_HEX64); } YY_BREAK case 38: YY_RULE_SETUP -#line 186 "scanner.l" +#line 190 "scanner.l" { return(TOK_ARRAY_START); } YY_BREAK case 39: YY_RULE_SETUP -#line 187 "scanner.l" +#line 191 "scanner.l" { return(TOK_ARRAY_END); } YY_BREAK case 40: YY_RULE_SETUP -#line 188 "scanner.l" +#line 192 "scanner.l" { return(TOK_LIST_START); } YY_BREAK case 41: YY_RULE_SETUP -#line 189 "scanner.l" +#line 193 "scanner.l" { return(TOK_LIST_END); } YY_BREAK case 42: YY_RULE_SETUP -#line 190 "scanner.l" +#line 194 "scanner.l" { return(TOK_SEMICOLON); } YY_BREAK case 43: @@ -1210,12 +1214,12 @@ case 43: yyg->yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 191 "scanner.l" +#line 195 "scanner.l" { /* ignore */ } YY_BREAK case 44: YY_RULE_SETUP -#line 192 "scanner.l" +#line 196 "scanner.l" { return(TOK_GARBAGE); } YY_BREAK case YY_STATE_EOF(INITIAL): @@ -1223,7 +1227,7 @@ case YY_STATE_EOF(COMMENT): case YY_STATE_EOF(STRING): case YY_STATE_EOF(INCLUDE): case YY_STATE_EOF(SCRIPTBLOCK): -#line 194 "scanner.l" +#line 198 "scanner.l" { YY_BUFFER_STATE buf = (YY_BUFFER_STATE)scanctx_pop_include( yyextra); @@ -1238,10 +1242,10 @@ case YY_STATE_EOF(SCRIPTBLOCK): YY_BREAK case 45: YY_RULE_SETUP -#line 205 "scanner.l" +#line 209 "scanner.l" ECHO; YY_BREAK -#line 1245 "scanner.c" +#line 1249 "scanner.c" case YY_END_OF_BUFFER: { @@ -1496,6 +1500,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else ret_val = EOB_ACT_CONTINUE_SCAN; +#ifndef __clang_analyzer__ + // FIXME: Clang's static analyzer complains about leaking the result of libconfig_yyrealloc if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); @@ -1503,6 +1509,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } +#endif // __clang_analyzer__ yyg->yy_n_chars += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; @@ -2375,4 +2382,4 @@ void libconfig_yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 205 "scanner.l" +#line 209 "scanner.l" diff --git a/3rdparty/libconfig/scanner.h b/3rdparty/libconfig/scanner.h index 181bc5c94..ac79ff5d1 100644 --- a/3rdparty/libconfig/scanner.h +++ b/3rdparty/libconfig/scanner.h @@ -334,7 +334,7 @@ extern int libconfig_yylex \ #undef YY_DECL #endif -#line 205 "scanner.l" +#line 209 "scanner.l" #line 340 "scanner.h" #undef libconfig_yyIN_HEADER diff --git a/Hercules.xcodeproj/project.pbxproj b/Hercules.xcodeproj/project.pbxproj index 30b30d992..c7326dc0f 100644 --- a/Hercules.xcodeproj/project.pbxproj +++ b/Hercules.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ A5380CD91856CF4A0090CBC4 /* core.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC694185643BB009EB79C /* core.c */; }; A5380CDA1856D0650090CBC4 /* socket.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC6BA185643BB009EB79C /* socket.c */; }; A5380CDB1856D0690090CBC4 /* malloc.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC6A3185643BB009EB79C /* malloc.c */; }; + A567612D185D11D700997C0D /* nullpo.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC6B2185643BB009EB79C /* nullpo.c */; }; A56CC68918564387009EB79C /* account_sql.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68118564387009EB79C /* account_sql.c */; }; A56CC68A18564387009EB79C /* ipban_sql.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68318564387009EB79C /* ipban_sql.c */; }; A56CC68B18564387009EB79C /* login.c in Sources */ = {isa = PBXBuildFile; fileRef = A56CC68518564387009EB79C /* login.c */; }; @@ -960,6 +961,7 @@ files = ( A58A5A1A185800CD0099683E /* strlib.c in Sources */, A5380CD91856CF4A0090CBC4 /* core.c in Sources */, + A567612D185D11D700997C0D /* nullpo.c in Sources */, A5380CD81856CE8A0090CBC4 /* console.c in Sources */, A58A5A19185800C20099683E /* des.c in Sources */, A5380CD71856CE3C0090CBC4 /* mapcache.c in Sources */, diff --git a/src/char/char.c b/src/char/char.c index 6534f484c..8d7ff1ab4 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -331,15 +331,15 @@ void set_char_offline(int char_id, int account_id) static int char_db_setoffline(DBKey key, DBData *data, va_list ap) { struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data); - int server = va_arg(ap, int); - if (server == -1) { + int server_id = va_arg(ap, int); + if (server_id == -1) { character->char_id = -1; character->server = -1; if(character->waiting_disconnect != INVALID_TIMER){ timer->delete(character->waiting_disconnect, chardb_waiting_disconnect); character->waiting_disconnect = INVALID_TIMER; } - } else if (character->server == server) + } else if (character->server == server_id) character->server = -2; //In some map server that we aren't connected to. return 0; } @@ -2209,7 +2209,6 @@ void loginif_on_ready(void) int parse_fromlogin(int fd) { struct char_session_data* sd = NULL; - int i; // only process data from the login-server if( fd != login_fd ) { @@ -2242,10 +2241,9 @@ int parse_fromlogin(int fd) { uint16 command = RFIFOW(fd,0); if( HPM->packetsc[hpParse_FromLogin] ) { - if( (i = HPM->parse_packets(fd,hpParse_FromLogin)) ) { - if( i == 1 ) continue; - if( i == 2 ) return 0; - } + int success = HPM->parse_packets(fd,hpParse_FromLogin); + if( success == 1 ) continue; + else if( success == 2 ) return 0; } switch( command ) { @@ -2316,6 +2314,8 @@ int parse_fromlogin(int fd) { break; case 0x2717: // account data + { + int i; if (RFIFOREST(fd) < 72) return 0; @@ -2358,6 +2358,7 @@ int parse_fromlogin(int fd) { } } RFIFOSKIP(fd,72); + } break; // login-server alive packet @@ -2385,6 +2386,7 @@ int parse_fromlogin(int fd) { int class_[MAX_CHARS]; int guild_id[MAX_CHARS]; int num; + int i; char* data; struct auth_node* node = (struct auth_node*)idb_get(auth_db, acc); @@ -3209,7 +3211,7 @@ int parse_frommap(int fd) SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) + if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) ) Sql_ShowDebug(sql_handle); else if( SQL->NumRows(sql_handle) == 0 ) { result = 1; // 1-player not found @@ -3217,15 +3219,13 @@ int parse_frommap(int fd) Sql_ShowDebug(sql_handle); result = 1; // 1-player not found } else { - char name[NAME_LENGTH]; int account_id, char_id; char* data; time_t unban_time; SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); - SQL->GetData(sql_handle, 2, &data, NULL); char_id = atoi(data); - SQL->GetData(sql_handle, 3, &data, NULL); unban_time = atol(data); + SQL->GetData(sql_handle, 1, &data, NULL); char_id = atoi(data); + SQL->GetData(sql_handle, 2, &data, NULL); unban_time = atol(data); if( login_fd <= 0 ) result = 3; // 3-login-server offline @@ -3465,7 +3465,6 @@ int parse_frommap(int fd) { struct status_change_data data; StringBuf buf; - int i; StrBuf->Init(&buf); StrBuf->Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", scdata_db); @@ -3905,7 +3904,6 @@ static void char_delete2_cancel(int fd, struct char_session_data* sd) int parse_char(int fd) { - int i; char email[40]; unsigned short cmd; int map_fd; @@ -3937,10 +3935,9 @@ int parse_char(int fd) #define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0) if( HPM->packetsc[hpParse_Char] ) { - if( (i = HPM->parse_packets(fd,hpParse_Char)) ) { - if( i == 1 ) continue; - if( i == 2 ) return 0; - } + int success = HPM->parse_packets(fd,hpParse_Char); + if( success == 1 ) continue; + else if( success == 2 ) return 0; } cmd = RFIFOW(fd,0); @@ -4043,6 +4040,7 @@ int parse_char(int fd) uint32 subnet_map_ip; struct auth_node* node; int server_id = 0; + int i; int slot = RFIFOB(fd,2); RFIFOSKIP(fd,3); @@ -4214,31 +4212,35 @@ int parse_char(int fd) #if PACKETVER >= 20120307 // S 0970 .24B .B .W .W case 0x970: + { + int result; FIFOSD_CHECK(31); #else // S 0067 .24B .B .B .B .B .B .B .B .W .W case 0x67: + { + int result; FIFOSD_CHECK(37); #endif if( !char_new ) //turn character creation on/off [Kevin] - i = -2; + result = -2; else #if PACKETVER >= 20120307 - i = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29)); + result = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29)); #else - i = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35)); + result = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35)); #endif //'Charname already exists' (-1), 'Char creation denied' (-2) and 'You are underaged' (-3) - if (i < 0) { + if (result < 0) { WFIFOHEAD(fd,3); WFIFOW(fd,0) = 0x6e; /* Others I found [Ind] */ /* 0x02 = Symbols in Character Names are forbidden */ /* 0x03 = You are not elegible to open the Character Slot. */ /* 0x0B = This service is only available for premium users. */ - switch (i) { + switch (result) { case -1: WFIFOB(fd,2) = 0x00; break; case -2: WFIFOB(fd,2) = 0xFF; break; case -3: WFIFOB(fd,2) = 0x01; break; @@ -4249,7 +4251,7 @@ int parse_char(int fd) int len; // retrieve data struct mmo_charstatus char_dat; - mmo_char_fromsql(i, &char_dat, false); //Only the short data is needed. + mmo_char_fromsql(result, &char_dat, false); //Only the short data is needed. // send to player WFIFOHEAD(fd,2+MAX_CHAR_BUF); @@ -4258,13 +4260,14 @@ int parse_char(int fd) WFIFOSET(fd,len); // add new entry to the chars list - sd->found_char[char_dat.slot] = i; // the char_id of the new char + sd->found_char[char_dat.slot] = result; // the char_id of the new char } #if PACKETVER >= 20120307 RFIFOSKIP(fd,31); #else RFIFOSKIP(fd,37); #endif + } break; // delete char @@ -4275,6 +4278,7 @@ int parse_char(int fd) if (cmd == 0x1fb) FIFOSD_CHECK(56); { int cid = RFIFOL(fd,2); + int i; #if PACKETVER >= 20110309 if( *pincode->enabled ){ // hack check struct online_char_data* character; @@ -4483,6 +4487,7 @@ int parse_char(int fd) { char* l_user = (char*)RFIFOP(fd,2); char* l_pass = (char*)RFIFOP(fd,26); + int i; l_user[23] = '\0'; l_pass[23] = '\0'; ARR_FIND( 0, ARRAYLENGTH(server), i, server[i].fd <= 0 ); diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 5f033f4d7..6bd8ca568 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -447,16 +447,16 @@ struct guild * inter_guild_fromsql(int guild_id) while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { int position; - struct guild_position* p; + struct guild_position *pos; SQL->GetData(sql_handle, 0, &data, NULL); position = atoi(data); if( position < 0 || position >= MAX_GUILDPOSITION ) continue;// invalid position - p = &g->position[position]; - SQL->GetData(sql_handle, 1, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH)); - SQL->GetData(sql_handle, 2, &data, NULL); p->mode = atoi(data); - SQL->GetData(sql_handle, 3, &data, NULL); p->exp_mode = atoi(data); - p->modified = GS_POSITION_UNMODIFIED; + pos = &g->position[position]; + SQL->GetData(sql_handle, 1, &data, &len); memcpy(pos->name, data, min(len, NAME_LENGTH)); + SQL->GetData(sql_handle, 2, &data, NULL); pos->mode = atoi(data); + SQL->GetData(sql_handle, 3, &data, NULL); pos->exp_mode = atoi(data); + pos->modified = GS_POSITION_UNMODIFIED; } //printf("- Read guild_alliance %d from sql \n",guild_id); @@ -1664,7 +1664,7 @@ static int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int ac int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,int account_id1,int account_id2,int flag) { // Could speed up - struct guild *g[2]; + struct guild *g[2] = { NULL }; int j,i; g[0] = inter_guild_fromsql(guild_id1); g[1] = inter_guild_fromsql(guild_id2); @@ -1675,25 +1675,19 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,int account_id1 if(g[0]==NULL || g[1]==NULL) return 0; - if(flag&GUILD_ALLIANCE_REMOVE) - { + if( flag&GUILD_ALLIANCE_REMOVE ) { // Remove alliance/opposition, in case of alliance, remove on both side - for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++) - { + for( i = 0; i < ((flag&GUILD_ALLIANCE_TYPE_MASK) ? 1 : 2); i++ ) { ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag&GUILD_ALLIANCE_TYPE_MASK) ); if( j < MAX_GUILDALLIANCE ) g[i]->alliance[j].guild_id = 0; } - } - else - { + } else { // Add alliance, in case of alliance, add on both side - for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++) - { + for( i = 0; i < ((flag&GUILD_ALLIANCE_TYPE_MASK) ? 1 : 2); i++ ) { // Search an empty slot ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == 0 ); - if( j < MAX_GUILDALLIANCE ) - { + if( j < MAX_GUILDALLIANCE ) { g[i]->alliance[j].guild_id=g[1-i]->guild_id; memcpy(g[i]->alliance[j].name,g[1-i]->name,NAME_LENGTH); // Set alliance type diff --git a/src/char/int_quest.c b/src/char/int_quest.c index ce63a5581..f8a05bc8f 100644 --- a/src/char/int_quest.c +++ b/src/char/int_quest.c @@ -38,6 +38,7 @@ struct quest *mapif_quests_fromsql(int char_id, int *count) { stmt = SQL->StmtMalloc(sql_handle); if (stmt == NULL) { SqlStmt_ShowDebug(stmt); + *count = 0; return NULL; } diff --git a/src/char/inter.c b/src/char/inter.c index 771b51602..63e1564ff 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -872,7 +872,7 @@ int inter_mapif_init(int fd) //-------------------------------------------------------- // broadcast sending -int mapif_broadcast(unsigned char *mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd) +int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd) { unsigned char *buf = (unsigned char*)aMalloc((len)*sizeof(unsigned char)); 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 d00f49864..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++ 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 @@ -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/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/config/renewal.h b/src/config/renewal.h index a7fd22c37..3b11aff74 100644 --- a/src/config/renewal.h +++ b/src/config/renewal.h @@ -13,6 +13,7 @@ * @INFO: This file holds general-purpose renewal settings, for class-specific ones check /src/config/classes folder **/ +//#define DISABLE_RENEWAL #ifndef DISABLE_RENEWAL /// game renewal server mode diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 533b3d860..283eb3a0d 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -543,16 +543,16 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc SQL->GetData(sql_handle, 3, &data, NULL); acc->sex = data[0]; SQL->GetData(sql_handle, 4, &data, NULL); safestrncpy(acc->email, data, sizeof(acc->email)); SQL->GetData(sql_handle, 5, &data, NULL); acc->group_id = atoi(data); - SQL->GetData(sql_handle, 6, &data, NULL); acc->state = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 6, &data, NULL); acc->state = (unsigned int)strtoul(data, NULL, 10); SQL->GetData(sql_handle, 7, &data, NULL); acc->unban_time = atol(data); SQL->GetData(sql_handle, 8, &data, NULL); acc->expiration_time = atol(data); - SQL->GetData(sql_handle, 9, &data, NULL); acc->logincount = strtoul(data, NULL, 10); + SQL->GetData(sql_handle, 9, &data, NULL); acc->logincount = (unsigned int)strtoul(data, NULL, 10); SQL->GetData(sql_handle, 10, &data, NULL); safestrncpy(acc->lastlogin, data, sizeof(acc->lastlogin)); SQL->GetData(sql_handle, 11, &data, NULL); safestrncpy(acc->last_ip, data, sizeof(acc->last_ip)); SQL->GetData(sql_handle, 12, &data, NULL); safestrncpy(acc->birthdate, data, sizeof(acc->birthdate)); SQL->GetData(sql_handle, 13, &data, NULL); acc->char_slots = (uint8)atoi(data); SQL->GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode)); - SQL->GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data); + SQL->GetData(sql_handle, 15, &data, NULL); acc->pincode_change = (unsigned int)atol(data); SQL->FreeResult(sql_handle); @@ -568,7 +568,6 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc while( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { - char* data; SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(acc->account_reg2[i].str, data, sizeof(acc->account_reg2[i].str)); SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(acc->account_reg2[i].value, data, sizeof(acc->account_reg2[i].value)); ++i; diff --git a/src/login/login.c b/src/login/login.c index 75247845d..feed7239b 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -140,8 +140,8 @@ static int waiting_disconnect_timer(int tid, int64 tick, int id, intptr_t data) static int online_db_setoffline(DBKey key, DBData *data, va_list ap) { struct online_login_data* p = DB->data2ptr(data); - int server = va_arg(ap, int); - if( server == -1 ) + int server_id = va_arg(ap, int); + if( server_id == -1 ) { p->char_server = -1; if( p->waiting_disconnect != INVALID_TIMER ) @@ -150,7 +150,7 @@ static int online_db_setoffline(DBKey key, DBData *data, va_list ap) p->waiting_disconnect = INVALID_TIMER; } } - else if( p->char_server == server ) + else if( p->char_server == server_id ) p->char_server = -2; //Char server disconnected. return 0; } @@ -948,7 +948,7 @@ int mmo_auth_new(const char* userid, const char* pass, const char sex, const cha //----------------------------------------------------- int mmo_auth(struct login_session_data* sd, bool isServer) { struct mmo_account acc; - int len; + size_t len; char ip[16]; ip2str(session[sd->fd]->client_addr, ip); @@ -1615,7 +1615,7 @@ int login_config_read(const char* cfgName) else if(!strcmpi(w1, "check_client_version")) login_config.check_client_version = (bool)config_switch(w2); else if(!strcmpi(w1, "client_version_to_connect")) - login_config.client_version_to_connect = strtoul(w2, NULL, 10); + login_config.client_version_to_connect = (unsigned int)strtoul(w2, NULL, 10); else if(!strcmpi(w1, "use_MD5_passwords")) login_config.use_md5_passwds = (bool)config_switch(w2); else if(!strcmpi(w1, "group_id_to_connect")) diff --git a/src/login/login.h b/src/login/login.h index 15edb14dc..494912698 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -23,8 +23,8 @@ enum E_LOGINSERVER_ST struct login_session_data { int account_id; - long login_id1; - long login_id2; + int login_id1; + int login_id2; char sex;// 'F','M','S' char userid[NAME_LENGTH]; diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 9d01b2b37..51c447ed9 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -993,7 +993,7 @@ ACMD(alive) *------------------------------------------*/ ACMD(kami) { - unsigned long color=0; + unsigned int color=0; memset(atcmd_output, '\0', sizeof(atcmd_output)); @@ -1009,7 +1009,7 @@ ACMD(kami) else intif->broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(info->command + 4) == 'b' || *(info->command + 4) == 'B') ? BC_BLUE : BC_YELLOW); } else { - if(!message || !*message || (sscanf(message, "%lx %199[^\n]", &color, atcmd_output) < 2)) { + if(!message || !*message || (sscanf(message, "%u %199[^\n]", &color, atcmd_output) < 2)) { clif->message(fd, msg_txt(981)); // Please enter color and message (usage: @kamic ). return false; } @@ -4278,9 +4278,9 @@ char* txt_time(unsigned int duration) else tlen += sprintf(tlen + temp1, msg_txt(224), minutes); // %d minutes if (seconds == 1) - tlen += sprintf(tlen + temp1, msg_txt(225), seconds); // and %d second + sprintf(tlen + temp1, msg_txt(225), seconds); // and %d second else if (seconds > 1) - tlen += sprintf(tlen + temp1, msg_txt(226), seconds); // and %d seconds + sprintf(tlen + temp1, msg_txt(226), seconds); // and %d seconds return temp1; } @@ -5200,7 +5200,8 @@ ACMD(clearcart) #define MAX_SKILLID_PARTIAL_RESULTS 5 #define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 /* "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33) */ ACMD(skillid) { - int skillen, idx, i, found = 0; + int idx, i, found = 0; + size_t skillen; DBIterator* iter; DBKey key; DBData *data; @@ -6061,7 +6062,7 @@ ACMD(npctalk) char name[NAME_LENGTH],mes[100],temp[100]; struct npc_data *nd; bool ifcolor=(*(info->command + 7) != 'c' && *(info->command + 7) != 'C')?0:1; - unsigned long color=0; + unsigned int color = 0; if (sd->sc.count && //no "chatting" while muted. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC_DEEP_SLEEP] || @@ -6075,7 +6076,7 @@ ACMD(npctalk) } } else { - if (!message || !*message || sscanf(message, "%lx %23[^,], %99[^\n]", &color, name, mes) < 3) { + if (!message || !*message || sscanf(message, "%u %23[^,], %99[^\n]", &color, name, mes) < 3) { clif->message(fd, msg_txt(1223)); // Please enter the correct parameters (usage: @npctalkc , ). return false; } @@ -8286,7 +8287,7 @@ void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommand clif->message(fd, msg_txt(273)); // "Commands available:" for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) { - unsigned int slen = 0; + size_t slen; switch( type ) { case COMMAND_CHARCOMMAND: @@ -8384,8 +8385,9 @@ ACMD(accinfo) { ACMD(set) { char reg[32], val[128]; struct script_data* data; - int toset = 0, len; + int toset = 0; bool is_str = false; + size_t len; if( !message || !*message || (toset = sscanf(message, "%31s %128[^\n]s", reg, val)) < 1 ) { clif->message(fd, msg_txt(1367)); // Usage: @set @@ -8746,16 +8748,16 @@ static inline void atcmd_channel_help(int fd, const char *command, bool can_crea /* [Ind/Hercules] */ ACMD(channel) { struct hChSysCh *channel; - char key[HCHSYS_NAME_LENGTH], sub1[HCHSYS_NAME_LENGTH], sub2[HCHSYS_NAME_LENGTH], sub3[HCHSYS_NAME_LENGTH]; + char subcmd[HCHSYS_NAME_LENGTH], sub1[HCHSYS_NAME_LENGTH], sub2[HCHSYS_NAME_LENGTH], sub3[HCHSYS_NAME_LENGTH]; unsigned char k = 0; sub1[0] = sub2[0] = sub3[0] = '\0'; - if( !message || !*message || sscanf(message, "%s %s %s %s", key, sub1, sub2, sub3) < 1 ) { + if( !message || !*message || sscanf(message, "%s %s %s %s", subcmd, sub1, sub2, sub3) < 1 ) { atcmd_channel_help(fd,command,( hChSys.allow_user_channel_creation || pc->has_permission(sd, PC_PERM_HCHSYS_ADMIN) )); return true; } - if( strcmpi(key,"create") == 0 && ( hChSys.allow_user_channel_creation || pc->has_permission(sd, PC_PERM_HCHSYS_ADMIN) ) ) { + if( strcmpi(subcmd,"create") == 0 && ( hChSys.allow_user_channel_creation || pc->has_permission(sd, PC_PERM_HCHSYS_ADMIN) ) ) { if( sub1[0] != '#' ) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' return false; @@ -8787,7 +8789,7 @@ ACMD(channel) { clif->chsys_join(channel,sd); - } else if ( strcmpi(key,"list") == 0 ) { + } else if ( strcmpi(subcmd,"list") == 0 ) { if( sub1[0] != '\0' && strcmpi(sub1,"colors") == 0 ) { char mout[40]; for( k = 0; k < hChSys.colors_count; k++ ) { @@ -8824,7 +8826,7 @@ ACMD(channel) { } dbi_destroy(iter); } - } else if ( strcmpi(key,"setcolor") == 0 ) { + } else if ( strcmpi(subcmd,"setcolor") == 0 ) { if( sub1[0] != '#' ) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' @@ -8855,7 +8857,7 @@ ACMD(channel) { channel->color = k; sprintf(atcmd_output, msg_txt(1413),sub1,hChSys.colors_name[k]);// '%s' channel color updated to '%s' clif->message(fd, atcmd_output); - } else if ( strcmpi(key,"leave") == 0 ) { + } else if ( strcmpi(subcmd,"leave") == 0 ) { if( sub1[0] != '#' ) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' @@ -8883,7 +8885,7 @@ ACMD(channel) { clif->chsys_left(sd->channels[k],sd); sprintf(atcmd_output, msg_txt(1426),sub1); // You've left the '%s' channel clif->message(fd, atcmd_output); - } else if ( strcmpi(key,"bindto") == 0 ) { + } else if ( strcmpi(subcmd,"bindto") == 0 ) { if( sub1[0] != '#' ) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' @@ -8903,7 +8905,7 @@ ACMD(channel) { sd->gcbind = sd->channels[k]; sprintf(atcmd_output, msg_txt(1431),sub1); // Your global chat is now binded to the '%s' channel clif->message(fd, atcmd_output); - } else if ( strcmpi(key,"unbind") == 0 ) { + } else if ( strcmpi(subcmd,"unbind") == 0 ) { if( sd->gcbind == NULL ) { clif->message(fd, msg_txt(1432));// Your global chat is not binded to any channel @@ -8914,7 +8916,7 @@ ACMD(channel) { clif->message(fd, atcmd_output); sd->gcbind = NULL; - } else if ( strcmpi(key,"ban") == 0 ) { + } else if ( strcmpi(subcmd,"ban") == 0 ) { struct map_session_data *pl_sd = NULL; struct hChSysBanEntry *entry = NULL; @@ -8935,7 +8937,7 @@ ACMD(channel) { return false; } - if (!message || !*message || sscanf(message, "%s %s %24[^\n]", key, sub1, sub2) < 1) { + if (!message || !*message || sscanf(message, "%s %s %24[^\n]", subcmd, sub1, sub2) < 1) { sprintf(atcmd_output, msg_txt(1434), sub2);// Player '%s' was not found clif->message(fd, atcmd_output); return false; @@ -8971,7 +8973,7 @@ ACMD(channel) { sprintf(atcmd_output, msg_txt(1437),pl_sd->status.name,sub1); // Player '%s' has now been banned from '%s' channel clif->message(fd, atcmd_output); - } else if ( strcmpi(key,"unban") == 0 ) { + } else if ( strcmpi(subcmd,"unban") == 0 ) { struct map_session_data *pl_sd = NULL; if( sub1[0] != '#' ) { @@ -9018,7 +9020,7 @@ ACMD(channel) { sprintf(atcmd_output, msg_txt(1441),pl_sd->status.name,sub1); // Player '%s' has now been unbanned from the '%s' channel clif->message(fd, atcmd_output); - } else if ( strcmpi(key,"unbanall") == 0 ) { + } else if ( strcmpi(subcmd,"unbanall") == 0 ) { if( sub1[0] != '#' ) { clif->message(fd, msg_txt(1405));// Channel name must start with a '#' return false; @@ -9047,7 +9049,7 @@ ACMD(channel) { sprintf(atcmd_output, msg_txt(1442),sub1); // Removed all bans from '%s' channel clif->message(fd, atcmd_output); - } else if ( strcmpi(key,"banlist") == 0 ) { + } else if ( strcmpi(subcmd,"banlist") == 0 ) { DBIterator *iter = NULL; DBKey key; DBData *data; @@ -9092,7 +9094,7 @@ ACMD(channel) { dbi_destroy(iter); - } else if ( strcmpi(key,"setopt") == 0 ) { + } else if ( strcmpi(subcmd,"setopt") == 0 ) { const char* opt_str[3] = { "None", "JoinAnnounce", @@ -9817,7 +9819,7 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message return true; } while(0); } - else if (*message == atcommand->at_symbol) { + else /*if (*message == atcommand->at_symbol)*/ { //atcmd_msg is constructed above differently for charcommands //it's copied from message if not a charcommand so it can //pass through the rest of the code compatible with both symbols @@ -10037,7 +10039,7 @@ void atcommand_config_read(const char* config_filename) { else { if( commandinfo->help == NULL ) { const char *str = config_setting_get_string(command); - int len = strlen(str); + size_t len = strlen(str); commandinfo->help = aMalloc( len * sizeof(char) ); safestrncpy(commandinfo->help, str, len); } diff --git a/src/map/battle.c b/src/map/battle.c index 94c8fe581..802d2ec02 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -335,11 +335,11 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d if( atk_elem == ELE_FIRE && battle->get_current_skill(target) == GN_WALLOFTHORN ) { struct skill_unit *su = (struct skill_unit*)target; struct skill_unit_group *sg; - struct block_list *src; + struct block_list *sgsrc; if( !su || !su->alive || (sg = su->group) == NULL || sg->val3 == -1 - || (src = map->id2bl(sg->src_id)) == NULL || status->isdead(src) + || (sgsrc = map->id2bl(sg->src_id)) == NULL || status->isdead(sgsrc) ) return 0; @@ -347,7 +347,7 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d int x,y; x = sg->val3 >> 16; y = sg->val3 & 0xffff; - skill->unitsetting(src,su->group->skill_id,su->group->skill_lv,x,y,1); + skill->unitsetting(sgsrc,su->group->skill_id,su->group->skill_lv,x,y,1); sg->val3 = -1; sg->limit = DIFF_TICK32(timer->gettick(),sg->tick)+300; } @@ -2332,11 +2332,12 @@ int battle_calc_skillratio(int attack_type, struct block_list *src, struct block break; case SR_RAMPAGEBLASTER: skillratio += 20 * skill_lv * (sd?sd->spiritball_old:5) - 100; - if( sc && sc->data[SC_EXPLOSIONSPIRITS] ){ + if( sc && sc->data[SC_EXPLOSIONSPIRITS] ) { skillratio += sc->data[SC_EXPLOSIONSPIRITS]->val1 * 20; RE_LVL_DMOD(120); - }else + } else { RE_LVL_DMOD(150); + } break; case SR_KNUCKLEARROW: if( flag&4 ){ // ATK [(Skill Level x 150) + (1000 x Target current weight / Maximum weight) + (Target Base Level x 5) x (Caster Base Level / 150)] % @@ -2600,10 +2601,10 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam if( sc->data[SC_SAFETYWALL] && (flag&(BF_SHORT|BF_MAGIC))==BF_SHORT ) { struct skill_unit_group* group = skill->id2group(sc->data[SC_SAFETYWALL]->val3); - uint16 skill_id = sc->data[SC_SAFETYWALL]->val2; + uint16 src_skill_id = sc->data[SC_SAFETYWALL]->val2; if (group) { d->dmg_lv = ATK_BLOCK; - if(skill_id == MH_STEINWAND){ + if(src_skill_id == MH_STEINWAND){ if (--group->val2<=0) skill->del_unitgroup(group,ALC_MARK); return 0; @@ -3638,12 +3639,12 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * md.damage = 7 * md.damage / 20; }*/ }else{ - float vitfactor = 0.0f, temp; + float vitfactor = 0.0f, ftemp; if( (vitfactor=(status_get_vit(target)-120.0f)) > 0) vitfactor = (vitfactor * (matk + atk) / 10) / status_get_vit(target); - temp = max(0, vitfactor) + (targetVit * (matk + atk)) / 10; - md.damage = (int64)(temp * 70 * skill_lv / 100); + ftemp = max(0, vitfactor) + (targetVit * (matk + atk)) / 10; + md.damage = (int64)(ftemp * 70 * skill_lv / 100); } md.damage -= totaldef; } @@ -4553,7 +4554,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list short index = sd?sd->equip_index[EQI_HAND_R]:0; GET_NORMAL_ATTACK( (sc && sc->data[SC_MAXIMIZEPOWER]?1:0)|(sc && sc->data[SC_WEAPONPERFECT]?8:0) ); wd.damage = wd.damage * 70 / 100; - n_ele = true; + //n_ele = true; // FIXME: This is has no effect if it's after GET_NORMAL_ATTACK (was this intended, or was it supposed to be put above?) if (sd && index >= 0 && sd->inventory_data[index] && @@ -5261,6 +5262,11 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st delay += 100;/* gradual increase so the numbers don't clip in the client */ } } + +#ifdef __clang_analyzer__ + // Tell Clang's static analyzer that we want to += it even the value is currently unused (it'd be used if we added new checks) + (void)delay; +#endif // __clang_analyzer /* something caused reflect */ if( trdamage ) { diff --git a/src/map/clif.c b/src/map/clif.c index a04ac0e27..e51c59461 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -578,12 +578,12 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target struct hQueue *queue = &script->hq[sd->bg_queue.arena->queue_id]; for( i = 0; i < queue->size; i++ ) { - struct map_session_data * sd = NULL; + struct map_session_data *qsd = NULL; - if( queue->item[i] > 0 && ( sd = map->id2sd(queue->item[i]) ) ) { - WFIFOHEAD(sd->fd,len); - memcpy(WFIFOP(sd->fd,0), buf, len); - WFIFOSET(sd->fd,len); + if( queue->item[i] > 0 && ( qsd = map->id2sd(queue->item[i]) ) ) { + WFIFOHEAD(qsd->fd,len); + memcpy(WFIFOP(qsd->fd,0), buf, len); + WFIFOSET(qsd->fd,len); } } } @@ -930,6 +930,8 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu struct view_data* vd = status->get_viewdata(bl); struct packet_idle_unit p; int g_id = status->get_guild_id(bl); + + nullpo_retv(bl); #if PACKETVER < 20091103 if( !pcdb_checkid(vd->class_) ) { @@ -1060,6 +1062,8 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { struct packet_spawn_unit p; int g_id = status->get_guild_id(bl); + nullpo_retv(bl); + #if PACKETVER < 20091103 if( !pcdb_checkid(vd->class_) ) { clif->spawn_unit2(bl,target); @@ -1123,6 +1127,7 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { } #endif if( disguised(bl) ) { + nullpo_retv(sd); if( sd->status.class_ != sd->disguise ) clif->send(&p,sizeof(p),bl,target); #if PACKETVER >= 20091103 @@ -1146,6 +1151,8 @@ void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, struct view_data* vd = status->get_viewdata(bl); struct packet_unit_walking p; int g_id = status->get_guild_id(bl); + + nullpo_retv(bl); sd = BL_CAST(BL_PC, bl); @@ -1831,7 +1838,7 @@ void clif_selllist(struct map_session_data *sd) /// - append this text void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes) { int fd = sd->fd; - int slen = strlen(mes) + 9; + size_t slen = strlen(mes) + 9; sd->state.dialog = 1; @@ -1943,7 +1950,7 @@ void clif_sendfakenpc(struct map_session_data *sd, int npcid) { /// TODO investigate behavior of other windows [FlavioJS] void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes) { int fd = sd->fd; - int slen = strlen(mes) + 9; + size_t slen = strlen(mes) + 9; struct block_list *bl = NULL; if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = map->id2bl(npcid)) && (bl->m!=sd->bl.m || @@ -2714,7 +2721,7 @@ void read_channels_config(void) { if( (colors = config_setting_get_member(settings, "colors")) != NULL ) { int color_count = config_setting_length(colors); - CREATE( hChSys.colors, unsigned long, color_count ); + CREATE( hChSys.colors, unsigned int, color_count ); CREATE( hChSys.colors_name, char *, color_count ); for(i = 0; i < color_count; i++) { config_setting_t *color = config_setting_get_elem(colors, i); @@ -2723,7 +2730,7 @@ void read_channels_config(void) { safestrncpy(hChSys.colors_name[i], config_setting_name(color), HCHSYS_NAME_LENGTH); - hChSys.colors[i] = strtoul(config_setting_get_string_elem(colors,i),NULL,0); + hChSys.colors[i] = (unsigned int)strtoul(config_setting_get_string_elem(colors,i),NULL,0); hChSys.colors[i] = (hChSys.colors[i] & 0x0000FF) << 16 | (hChSys.colors[i] & 0x00FF00) | (hChSys.colors[i] & 0xFF0000) >> 16;//RGB to BGR } hChSys.colors_count = color_count; @@ -3141,7 +3148,7 @@ void clif_changelook(struct block_list *bl,int type,int val) sd = BL_CAST(BL_PC, bl); sc = status->get_sc(bl); vd = status->get_viewdata(bl); - //nullpo_ret(vd); + if( vd ) //temp hack to let Warp Portal change appearance switch(type) { case LOOK_WEAPON: @@ -3250,6 +3257,7 @@ void clif_changelook(struct block_list *bl,int type,int val) WBUFW(buf,0)=0x1d7; WBUFL(buf,2)=bl->id; if(type == LOOK_WEAPON || type == LOOK_SHIELD) { + nullpo_retv(vd); WBUFB(buf,6)=LOOK_WEAPON; WBUFW(buf,7)=vd->weapon; WBUFW(buf,9)=vd->shield; @@ -3258,7 +3266,7 @@ void clif_changelook(struct block_list *bl,int type,int val) WBUFL(buf,7)=val; } clif->send(buf,packet_len(0x1d7),bl,target); - if( disguised(bl) && ((TBL_PC*)sd)->fontcolor ) { + if( disguised(bl) && sd && sd->fontcolor ) { WBUFL(buf,2)=-bl->id; clif->send(buf,packet_len(0x1d7),bl,SELF); } @@ -4696,6 +4704,7 @@ int clif_outsight(struct block_list *bl,va_list ap) tsd = BL_CAST(BL_PC, tbl); if (tsd && tsd->fd) { //tsd has lost sight of the bl object. + nullpo_ret(bl); switch(bl->type){ case BL_PC: if (sd->vd.class_ != INVISIBLE_CLASS) @@ -4728,6 +4737,7 @@ int clif_outsight(struct block_list *bl,va_list ap) } } if (sd && sd->fd) { //sd is watching tbl go out of view. + nullpo_ret(tbl); if (((vd=status->get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) && !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->option&OPTION_INVISIBLE))) clif->clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd); @@ -4750,6 +4760,7 @@ int clif_insight(struct block_list *bl,va_list ap) tsd = BL_CAST(BL_PC, tbl); if (tsd && tsd->fd) { //Tell tsd that bl entered into his view + nullpo_ret(bl); switch(bl->type) { case BL_ITEM: clif->getareachar_item(tsd,(struct flooritem_data*)bl); @@ -5528,7 +5539,7 @@ void clif_displaymessage(const int fd, const char* mes) { if( fd == -2 ) { ShowInfo("HCP: %s\n",mes); } else if ( fd > 0 ) { - int len; + size_t len; if ( ( len = strnlen(mes, 255) ) > 0 ) { // don't send a void message (it's not displaying on the client chat). @help can send void line. WFIFOHEAD(fd, 5 + len); @@ -5554,7 +5565,7 @@ void clif_displaymessage2(const int fd, const char* mes) { line = strtok(message, "\n"); while(line != NULL) { // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client) - int len = strnlen(line, 255); + size_t len = strnlen(line, 255); if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line. if( fd == -2 ) { @@ -5606,7 +5617,7 @@ void clif_displaymessage_sprintf(const int fd, const char* mes, ...) { } /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST). /// 009a .W .?B -void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target) +void clif_broadcast(struct block_list* bl, const char* mes, size_t len, int type, enum send_target target) { int lp = (type&BC_COLOR_MASK) ? 4 : 0; unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char)); @@ -5630,7 +5641,7 @@ void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, e *------------------------------------------*/ void clif_GlobalMessage(struct block_list* bl, const char* message) { char buf[256]; - int len; + size_t len; nullpo_retv(bl); if(!message) @@ -5653,7 +5664,7 @@ void clif_GlobalMessage(struct block_list* bl, const char* message) { /// Send broadcast message with font formatting (ZC_BROADCAST2). /// 01c3 .W .L .W .W .W .W .?B -void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target) +void clif_broadcast2(struct block_list* bl, const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target) { unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char)); @@ -5829,7 +5840,7 @@ void clif_upgrademessage(int fd, int result, int item_id) /// Whisper is transmitted to the destination player (ZC_WHISPER). /// 0097 .W .24B .?B /// 0097 .W .24B .L .?B (PACKETVER >= 20091104) -void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len) { +void clif_wis_message(int fd, const char* nick, const char* mes, size_t mes_len) { #if PACKETVER < 20091104 WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4); WFIFOW(fd,0) = 0x97; @@ -8053,14 +8064,14 @@ void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_sess /*========================================== * *------------------------------------------*/ -void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len) { +void clif_disp_onlyself(struct map_session_data *sd, const char *mes, size_t len) { clif->disp_message(&sd->bl, mes, len, SELF); } /*========================================== * Displays a message using the guild-chat colors to the specified targets. [Skotlex] *------------------------------------------*/ -void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target) +void clif_disp_message(struct block_list* src, const char* mes, size_t len, enum send_target target) { unsigned char buf[256]; @@ -8317,7 +8328,7 @@ void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, sen // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead) /// 02c1 .W .L .L .?B int clif_colormes(int fd, enum clif_colors color, const char* msg) { - unsigned short msg_len = strlen(msg) + 1; + size_t msg_len = strlen(msg) + 1; WFIFOHEAD(fd,msg_len + 12); WFIFOW(fd,0) = 0x2C1; @@ -8332,8 +8343,8 @@ int clif_colormes(int fd, enum clif_colors color, const char* msg) { /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT). /// 02c1 .W .L .L .?B -void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) { - unsigned short msg_len = strlen(msg) + 1; +void clif_messagecolor(struct block_list* bl, unsigned int color, const char* msg) { + size_t msg_len = strlen(msg) + 1; uint8 buf[256]; color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR @@ -8657,7 +8668,7 @@ void clif_slide(struct block_list *bl, int x, int y) void clif_disp_overhead(struct block_list *bl, const char* mes) { unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap) - int len_mes = strlen(mes)+1; //Account for \0 + size_t len_mes = strlen(mes)+1; //Account for \0 if (len_mes > sizeof(buf)-8) { ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes); @@ -8946,9 +8957,10 @@ void clif_viewequip_fail(struct map_session_data* sd) /// Returns true if the packet was parsed successfully. /// Formats: 0 - .w .w ( : ).?B 00 /// 1 - .w .w .24B .?B 00 -bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_) { +bool clif_process_message(struct map_session_data *sd, int format, char **name_, size_t *namelen_, char **message_, size_t *messagelen_) { char *text, *name, *message; - unsigned int packetlen, textlen, namelen, messagelen; + unsigned int packetlen, textlen; + size_t namelen, messagelen; int fd = sd->fd; *name_ = NULL; @@ -9604,7 +9616,7 @@ void clif_parse_Hotkey(int fd, struct map_session_data *sd) { /// Displays cast-like progress bar (ZC_PROGRESS). /// 02f0 .L