From f2fd4885c2a906414e0f36acf95d252e5a9d5805 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 8 Jan 2013 19:00:34 -0800 Subject: Improve warning management more --- src/map/atcommand.cpp | 18 +++++++----------- src/map/atcommand.hpp | 3 +++ src/map/battle.cpp | 6 ------ src/map/chrif.cpp | 1 - src/map/chrif.hpp | 3 +++ src/map/clif.cpp | 8 +++++--- src/map/intif.cpp | 1 - src/map/magic-expr.cpp | 2 +- src/map/magic-interpreter-base.cpp | 13 +++++++++---- src/map/magic-stmt.cpp | 3 ++- src/map/magic.hpp | 2 +- src/map/map.cpp | 5 +++-- src/map/map.hpp | 6 +++--- src/map/mob.cpp | 7 ++----- src/map/mob.hpp | 2 +- src/map/npc.cpp | 2 +- src/map/pc.cpp | 7 +++++-- src/map/script.cpp | 12 +++++++++--- src/map/skill.cpp | 23 +++++++++++++++++++---- src/map/storage.cpp | 4 ++-- src/map/trade.cpp | 2 -- 21 files changed, 76 insertions(+), 54 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index fa3d23d..46c0e9e 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -5190,7 +5190,6 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "Please, enter at least a valid list number (usage: @mapinfo <0-3> [map])."); return -1; - break; } return 0; @@ -6424,7 +6423,6 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, { // replace trailing ", " #ifdef ANNOYING_GCC46_WORKAROUNDS -# warning " and " output.resize(output.size() - 1); #else output.pop_back(); @@ -6550,7 +6548,6 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd, { // replace last ", " #ifdef ANNOYING_GCC46_WORKAROUNDS -# warning " all of " output.resize(output.size() - 1); #else output.pop_back(); @@ -6680,7 +6677,6 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd, if (!output.empty()) { #ifdef ANNOYING_GCC46_WORKAROUNDS -# warning " these ... " output.resize(output.size() - 1); #else output.pop_back(); @@ -6764,7 +6760,7 @@ int atcommand_charkillable(const int fd, struct map_session_data *, if (!message || !*message) return -1; - if ((pl_sd = map_nick2sd((char *) message)) == NULL) + if ((pl_sd = map_nick2sd(message)) == NULL) return -1; pl_sd->special_state.killable = !pl_sd->special_state.killable; @@ -6889,7 +6885,7 @@ int atcommand_chareffect(const int fd, struct map_session_data *, return -1; } - if ((pl_sd = map_nick2sd((char *) target)) == NULL) + if ((pl_sd = map_nick2sd(target)) == NULL) return -1; clif_specialeffect(&pl_sd->bl, type, 0); @@ -6935,7 +6931,7 @@ int atcommand_chardropall(const int fd, struct map_session_data *, if (!message || !*message) return -1; - if ((pl_sd = map_nick2sd((char *) message)) == NULL) + if ((pl_sd = map_nick2sd(message)) == NULL) return -1; for (i = 0; i < MAX_INVENTORY; i++) { @@ -7009,7 +7005,7 @@ int atcommand_charstoreall(const int fd, struct map_session_data *sd, if (!message || !*message) return -1; - if ((pl_sd = map_nick2sd((char *) message)) == NULL) + if ((pl_sd = map_nick2sd(message)) == NULL) return -1; if (storage_storageopen(pl_sd) == 1) @@ -7297,7 +7293,7 @@ int atcommand_adjgmlvl(const int fd, struct map_session_data *, return -1; } - if ((pl_sd = map_nick2sd((char *) user)) == NULL) + if ((pl_sd = map_nick2sd(user)) == NULL) return -1; pc_set_gm_level(pl_sd->status.account_id, newlev); @@ -7321,7 +7317,7 @@ int atcommand_trade(const int, struct map_session_data *sd, if (!message || !*message) return -1; - if ((pl_sd = map_nick2sd((char *) message)) != NULL) + if ((pl_sd = map_nick2sd(message)) != NULL) { trade_traderequest(sd, pl_sd->bl.id); return 0; @@ -7340,7 +7336,7 @@ int atcommand_unmute(const int, struct map_session_data *sd, if (!message || !*message) return -1; - if ((pl_sd = map_nick2sd((char *) message)) != NULL) + if ((pl_sd = map_nick2sd(message)) != NULL) { if (pl_sd->sc_data[SC_NOCHAT].timer != -1) { diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index ec69cc7..4d3b592 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -199,4 +199,7 @@ int atcommand_config_read(const char *cfgName); void log_atcommand(struct map_session_data *sd, const_string cmd); +// only used by map.cpp +extern char *gm_logfile_name; + #endif // ATCOMMAND_HPP diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 3b57d13..7da685f 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -176,7 +176,6 @@ int battle_get_max_hp(struct block_list *bl) max_hp = 1; return max_hp; } - return 1; } /*========================================== @@ -685,7 +684,6 @@ int battle_get_atk2(struct block_list *bl) atk2 = 0; return atk2; } - return 0; } /*========================================== @@ -993,8 +991,6 @@ int battle_get_speed(struct block_list *bl) speed = 1; return speed; } - - return 1000; } /*========================================== @@ -1075,7 +1071,6 @@ int battle_get_adelay(struct block_list *bl) adelay = battle_config.monster_max_aspd << 1; return adelay; } - return 4000; } int battle_get_amotion(struct block_list *bl) @@ -1140,7 +1135,6 @@ int battle_get_amotion(struct block_list *bl) amotion = battle_config.monster_max_aspd; return amotion; } - return 2000; } int battle_get_dmotion(struct block_list *bl) diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 41c1381..6ab786c 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -34,7 +34,6 @@ const int packet_len_table[0x20] = { }; int char_fd; -int srvinfo; static char char_ip_str[16]; static diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp index 7c4a431..dce1ae3 100644 --- a/src/map/chrif.hpp +++ b/src/map/chrif.hpp @@ -30,4 +30,7 @@ int chrif_send_divorce(int char_id); int do_init_chrif (void); +// only used by intif.cpp +extern int char_fd; + #endif // CHRIF_HPP diff --git a/src/map/clif.cpp b/src/map/clif.cpp index e306c23..edae508 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -140,7 +140,6 @@ static struct in_addr map_ip; static int map_port = 5121; -int map_fd; char talkie_mes[80]; static @@ -264,7 +263,7 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, clif_emotion_towards(src_bl, bl, EMOTE_IGNORED); return; } - /* fall through... */ + FALLTHROUGH; case AREA_WOC: if ((sd && sd->chatID) || (bl && bl == src_bl)) return; @@ -414,6 +413,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) y0 = bl->y - AREA_SIZE; x1 = bl->x + AREA_SIZE; y1 = bl->y + AREA_SIZE; + FALLTHROUGH; case PARTY: // 全パーティーメンバに送信 case PARTY_WOS: // 自分以外の全パーティーメンバに送信 case PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信 @@ -3719,7 +3719,8 @@ int clif_party_leaved(struct party *p, struct map_session_data *sd, */ int clif_party_message(struct party *p, int account_id, const char *mes, int len) { - struct map_session_data *sd; + // always set, but clang is not smart enough + struct map_session_data *sd = nullptr; int i; nullpo_ret(p); @@ -5557,6 +5558,7 @@ typedef struct func_table int rate; } func_table; // *INDENT-OFF* +static func_table clif_parse_func_table[0x220] = { { NULL, 0 }, // 0 diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 44d381b..bb27643 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -40,7 +40,6 @@ const int packet_len_table[] = { 11, -1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -extern int char_fd; // inter serverのfdはchar_fdを使う #define inter_fd char_fd // エイリアス //----------------------------------------------------------------- diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 904d4a4..6712af3 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -1310,7 +1310,7 @@ int functions_are_sorted = 0; static int compare_fun(const void *lhs, const void *rhs) { - return strcmp(((fun_t *) lhs)->name, ((fun_t *) rhs)->name); + return strcmp(((const fun_t *) lhs)->name, ((const fun_t *) rhs)->name); } fun_t *magic_get_fun(const char *name, int *index) diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index f0fc6e9..57f6fe6 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -10,6 +10,9 @@ void set_int_p(val_t *v, int i, TY t) v->v.v_int = i; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-macros" + #define set_int(v, i) set_int_p(v, i, TY_INT) #define set_dir(v, i) set_int_p(v, i, TY_DIR) @@ -46,6 +49,8 @@ void set_spell SETTER(spell_t *, TY_SPELL, v_spell) #define set_env_invocation(v, x) setenv(set_invocation, v, x) #define set_env_spell(v, x) setenv(set_spell, v, x) +#pragma GCC diagnostic pop + magic_conf_t magic_conf; /* Global magic conf */ env_t magic_default_env = { &magic_conf, NULL }; @@ -66,8 +71,8 @@ const char *magic_find_invocation(const char *spellname) static int spell_compare(const void *lhs, const void *rhs) { - return strcmp((*((spell_t **) lhs))->invocation, - (*((spell_t **) rhs))->invocation); + return strcmp((*((const spell_t *const*) lhs))->invocation, + (*((const spell_t *const*) rhs))->invocation); } spell_t *magic_find_spell(char *invocation) @@ -103,8 +108,8 @@ spell_t *magic_find_spell(char *invocation) static int compare_teleport_anchor(const void *lhs, const void *rhs) { - return strcmp((*((teleport_anchor_t **) lhs))->invocation, - (*((teleport_anchor_t **) rhs))->invocation); + return strcmp((*((const teleport_anchor_t *const*) lhs))->invocation, + (*((const teleport_anchor_t *const*) rhs))->invocation); } const char *magic_find_anchor_invocation(const char *anchor_name) diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index de4a15e..e911f92 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -897,7 +897,7 @@ int operation_count; static int compare_operations(const void *lhs, const void *rhs) { - return strcmp(((op_t *) lhs)->name, ((op_t *) rhs)->name); + return strcmp(((const op_t *) lhs)->name, ((const op_t *) rhs)->name); } op_t *magic_get_op(char *name, int *index) @@ -1406,6 +1406,7 @@ int spell_run(invocation_t *invocation, int allow_delete) case EFFECT_ABORT: invocation->flags |= INVOCATION_FLAG_ABORTED; invocation->end_effect = NULL; + FALLTHROUGH; case EFFECT_END: clear_stack(invocation); next = NULL; diff --git a/src/map/magic.hpp b/src/map/magic.hpp index 4cdce18..848ba46 100644 --- a/src/map/magic.hpp +++ b/src/map/magic.hpp @@ -36,7 +36,7 @@ void magic_unshroud(character_t *character); * * \param invocation The invocation to notify * \param bl_id ID of the PC for whom this happened - * \param type sc_id ID of the status change entry that finished + * \param sc_id ID of the status change entry that finished * \param supplanted Whether the status_change finished normally (0) or was supplanted by a new status_change (1) */ void spell_effect_report_termination(int invocation, int bl_id, diff --git a/src/map/map.cpp b/src/map/map.cpp index e1b96a8..8732186 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -65,6 +65,7 @@ int bl_list_count = 0; struct map_data map[MAX_MAP_PER_SERVER]; int map_num = 0; +static int map_port = 0; int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; @@ -1736,11 +1737,11 @@ int map_delmap(const char *mapname) return 0; } -extern char *gm_logfile_name; - #define LOGFILE_SECONDS_PER_CHUNK_SHIFT 10 +static FILE *map_logfile = NULL; +static char *map_logfile_name = NULL; static long map_logfile_index; diff --git a/src/map/map.hpp b/src/map/map.hpp index 3d15bb5..8f534f5 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -701,10 +701,10 @@ int map_quit(struct map_session_data *); int map_addnpc(int, struct npc_data *); void map_log(const_string line); -#define MAP_LOG(format, args...) \ - map_log(static_cast(STRPRINTF(format, ##args))); +#define MAP_LOG(format, ...) \ + map_log(static_cast(STRPRINTF(format, ## __VA_ARGS__))) -#define MAP_LOG_PC(sd, fmt, args...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## args) +#define MAP_LOG_PC(sd, fmt, ...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## __VA_ARGS__) // 床アイテム関連 void map_clearflooritem_timer(timer_id, tick_t, custom_id_t, custom_data_t); diff --git a/src/map/mob.cpp b/src/map/mob.cpp index df739a8..06026de 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -21,10 +21,6 @@ #include "pc.hpp" #include "skill.hpp" -#ifndef max -#define max( a, b ) (((a) > (b)) ? (a) : (b) ) -#endif - #define MIN_MOBTHINKTIME 100 #define MOB_LAZYMOVEPERC 50 // Move probability in the negligent mode MOB (rate of 1000 minute) @@ -4606,7 +4602,8 @@ int mob_readskilldb(void) { char *sp[20], *p; int mob_id; - struct mob_skill *ms; + // always initialized, but clang is not smart enough yet + struct mob_skill *ms = nullptr; int j = 0; if (line[0] == '/' && line[1] == '/') diff --git a/src/map/mob.hpp b/src/map/mob.hpp index 70fcf06..6cedb1e 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -21,7 +21,7 @@ struct mob_skill MSC cond1; int cond2i; StatusChange cond2sc() { return StatusChange(cond2i); } - SkillID cond2sk() { return SkillID(cond2i); }; + SkillID cond2sk() { return SkillID(cond2i); } MST target; int val[5]; short emotion; diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 8966d49..0e406c2 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -2054,7 +2054,7 @@ void npc_free(struct npc_data *nd) static void ev_release(db_key_t key, db_val_t val) { - free((char*)key.s); + free(key.ms); free(val); } diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 5780525..2c8a4e7 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -3106,6 +3106,7 @@ int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val) sd->random_attack_increase_per += val; break; } // end addition + break; default: if (battle_config.error_log) PRINTF("pc_bonus2: unknown type %d %d %d!\n", @@ -4784,7 +4785,8 @@ int pc_checkbaselevelup(struct map_session_data *sd) //レベルアップしたのでパーティー情報を更新する //(公平範囲チェック) party_send_movemap(sd); - MAP_LOG_XP(sd, "LEVELUP") return 1; + MAP_LOG_XP(sd, "LEVELUP"); + return 1; } return 0; @@ -8496,5 +8498,6 @@ int pc_logout(struct map_session_data *sd) // [fate] Player logs out #endif pc_setglobalreg(sd, "MAGIC_CAST_TICK", 0); - MAP_LOG_STATS(sd, "LOGOUT") return 0; + MAP_LOG_STATS(sd, "LOGOUT"); + return 0; } diff --git a/src/map/script.cpp b/src/map/script.cpp index 25db80b..eca91e6 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -46,7 +46,9 @@ ScriptCode *script_buf; static int script_pos, script_size; +static char *str_buf; +static int str_pos, str_size; static struct str_data_t @@ -59,7 +61,9 @@ struct str_data_t int val; int next; } *str_data; +static int str_num = LABEL_START, str_data_size; +static int str_hash[16]; static @@ -449,7 +453,8 @@ void disp_error_message(const char *mes, const char *pos_) { const char *linestart = p; char *lineend = const_cast(strchr(p, '\n')); - char c; + // always initialized, but clang is not smart enough + char c = '\0'; if (lineend) { c = *lineend; @@ -2374,6 +2379,7 @@ void builtin_strcharinfo(ScriptState *st) // indexed by the equip_* in db/const.txt // TODO change to use EQUIP +static EPOS equip[10] = { EPOS::HAT, @@ -4128,7 +4134,7 @@ void builtin_message(ScriptState *st) const char *player = conv_str(st, &(st->stack->stack_data[st->start + 2])); const char *msg = conv_str(st, &(st->stack->stack_data[st->start + 3])); - if ((pl_sd = map_nick2sd((char *) player)) == NULL) + if ((pl_sd = map_nick2sd(player)) == NULL) return; clif_displaymessage(pl_sd->fd, msg); @@ -4741,7 +4747,7 @@ void run_script_main(const ScriptCode *script, int pos_, int, int, break; case ScriptCode::POS: case ScriptCode::NAME: - push_val(stack, c, (*(int *)(script + st->pos)) & 0xffffff); + push_val(stack, c, (*(const int *)(script + st->pos)) & 0xffffff); st->pos += 3; break; case ScriptCode::ARG: diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 68f27fc..98b6f7d 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -2549,7 +2549,9 @@ void skill_timer(timer_id, tick_t tick, custom_id_t id, custom_data_t data) case RG_INTIMIDATE: if (sd && !map[src->m].flag.noteleport) { - int x, y, i, j, c; + // always initialized, but clang is not smart enough + int x = 0, y = 0; + int i, j, c; pc_randomwarp(sd, 3); for (i = 0; i < 16; i++) { @@ -2578,7 +2580,9 @@ void skill_timer(timer_id, tick_t tick, custom_id_t id, custom_data_t data) } else if (md && !map[src->m].flag.monster_noteleport) { - int x, y, i, j, c; + // always initialized, but clang isn't smart enough + int x = 0, y = 0; + int i, j, c; mob_warp(md, -1, -1, -1, 3); for (i = 0; i < 16; i++) { @@ -7998,6 +8002,8 @@ int skill_use_id(struct map_session_data *sd, int target_id, sd->skilllv_old = sd->skilllv; break; } + // TODO: determine if this was supposed to fallthrough instead + break; case BD_ENCORE: /* アンコール */ if (sd->skillid_dance == SkillID::ZERO) { //前回使用した踊りがないとだめ @@ -8896,6 +8902,8 @@ void skill_trap_splash(struct block_list *bl, sg->skill_lv, tick, (sg->val2) ? BCT_mid_x05 : BCT_ZERO); } + // TODO: determine if this was supposed to break + FALLTHROUGH; case 0x97: /* フリージングトラップ */ skill_attack(BF_WEAPON, ss, src, bl, sg->skill_id, sg->skill_lv, tick, (sg->val2) ? BCT_mid_x05 : BCT_ZERO); @@ -9812,7 +9820,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, Opt3 *opt3; int opt_flag = 0, calc_flag = 0; int race, mode, elem, undead_flag; - SP updateflag; + SP updateflag = SP::ZERO; int scdef = 0; nullpo_ret(bl); @@ -10044,6 +10052,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, calc_flag = 1; if (tick <= 0) tick = 1000; /* (オートバーサーク) */ + break; case SC_GLORIA: /* グロリア */ calc_flag = 1; break; @@ -10245,6 +10254,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, case SC_SPEEDPOTION0: /* 増速ポーション */ *opt2 |= Opt2::_speedpotion0; + FALLTHROUGH; case SC_SPEEDPOTION1: case SC_SPEEDPOTION2: calc_flag = 1; @@ -10255,6 +10265,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, /* atk & matk potions [Valaris] */ case SC_ATKPOT: *opt2 |= Opt2::_atkpot; + FALLTHROUGH; case SC_MATKPOT: calc_flag = 1; tick = 1000 * tick; @@ -10528,6 +10539,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, break; case SC_HASTE: calc_flag = 1; + break; case SC_SPLASHER: /* ベナムスプラッシャー */ case SC_PHYS_SHIELD: case SC_MBARRIER: @@ -11273,7 +11285,8 @@ void skill_unit_timer_sub(struct block_list *bl, unsigned int tick) case 0x99: /* トーキーボックス */ { struct block_list *src = map_id2bl(group->src_id); - if (group->unit_id == 0x91 && group->val2); + if (group->unit_id == 0x91 && group->val2) + ; else { if (src && src->type == BL_PC) @@ -11286,6 +11299,8 @@ void skill_unit_timer_sub(struct block_list *bl, unsigned int tick) } } } + // TODO: determine if this was supposed to be break + FALLTHROUGH; default: skill_delunit(unit); } diff --git a/src/map/storage.cpp b/src/map/storage.cpp index df228d1..d212c9d 100644 --- a/src/map/storage.cpp +++ b/src/map/storage.cpp @@ -28,8 +28,8 @@ struct dbt *storage_db; static int storage_comp_item(const void *_i1, const void *_i2) { - struct item *i1 = (struct item *) _i1; - struct item *i2 = (struct item *) _i2; + const struct item *i1 = (const struct item *) _i1; + const struct item *i2 = (const struct item *) _i2; if (i1->nameid == i2->nameid) return 0; diff --git a/src/map/trade.cpp b/src/map/trade.cpp index d5be2ad..6b44752 100644 --- a/src/map/trade.cpp +++ b/src/map/trade.cpp @@ -310,8 +310,6 @@ void trade_tradecancel(struct map_session_data *sd) } } -#define MAP_LOG_PC(sd, fmt, args...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## args) - /*========================================== * 取引許諾(trade押し) *------------------------------------------ -- cgit v1.2.3-60-g2f50