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 --- 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 +- 25 files changed, 611 insertions(+), 524 deletions(-) (limited to 'src/map') 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