diff options
author | Haru <haru@dotalux.com> | 2015-05-17 02:35:40 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-05-17 02:35:53 +0200 |
commit | b9a8ad743a78d5053482cb4d47d2795252ec9095 (patch) | |
tree | 40d10510054cd3dd254c366ccbe550817cb3e4ec | |
parent | b2b597c523f19fbacaf052117d47f254483c6e0e (diff) | |
download | hercules-b9a8ad743a78d5053482cb4d47d2795252ec9095.tar.gz hercules-b9a8ad743a78d5053482cb4d47d2795252ec9095.tar.bz2 hercules-b9a8ad743a78d5053482cb4d47d2795252ec9095.tar.xz hercules-b9a8ad743a78d5053482cb4d47d2795252ec9095.zip |
Fixed some issues detected by coverity scan
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/char/char.c | 2 | ||||
-rw-r--r-- | src/char/geoip.c | 22 | ||||
-rw-r--r-- | src/char/int_storage.c | 2 | ||||
-rw-r--r-- | src/common/grfio.c | 1 | ||||
-rw-r--r-- | src/map/battle.c | 9 | ||||
-rw-r--r-- | src/map/channel.c | 2 | ||||
-rw-r--r-- | src/map/elemental.c | 4 | ||||
-rw-r--r-- | src/map/homunculus.c | 2 | ||||
-rw-r--r-- | src/map/intif.c | 6 | ||||
-rw-r--r-- | src/map/npc.c | 19 | ||||
-rw-r--r-- | src/map/pet.c | 16 | ||||
-rw-r--r-- | src/map/script.c | 4 |
12 files changed, 47 insertions, 42 deletions
diff --git a/src/char/char.c b/src/char/char.c index d97cd33a9..d8d9d386e 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -1147,7 +1147,7 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every struct s_friend tmp_friend; #ifdef HOTKEY_SAVING struct hotkey tmp_hotkey; - int hotkey_num; + int hotkey_num = 0; #endif unsigned int opt; int account_id; diff --git a/src/char/geoip.c b/src/char/geoip.c index 889958e16..5d3324ab2 100644 --- a/src/char/geoip.c +++ b/src/char/geoip.c @@ -145,18 +145,20 @@ void geoip_init(void) } // Search database type - fseek(db, -3l, SEEK_END); - for (i = 0; i < GEOIP_STRUCTURE_INFO_MAX_SIZE; i++) { - if (fread(delim, sizeof(delim[0]), 3, db) != 3) { - db_type = 0; - break; - } - if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255) { - if (fread(&db_type, sizeof(db_type), 1, db) != 1) { + if (fseek(db, -3l, SEEK_END) != 0) { + db_type = 0; + } else { + for (i = 0; i < GEOIP_STRUCTURE_INFO_MAX_SIZE; i++) { + if (fread(delim, sizeof(delim[0]), 3, db) != 3) { db_type = 0; + break; + } + if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255) { + if (fread(&db_type, sizeof(db_type), 1, db) != 1) { + db_type = 0; + } + break; } - break; - } else { if (fseek(db, -4l, SEEK_CUR) != 0) { db_type = 0; break; diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 7afafc406..2584be0cf 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -303,7 +303,7 @@ int mapif_parse_ItemBoundRetrieve_sub(int fd) SQL->StmtBindColumn(stmt, 10+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL); while( SQL_SUCCESS == SQL->StmtNextRow(stmt)) { - Assert_retb(i >= MAX_INVENTORY); + Assert_retb(i < MAX_INVENTORY); memcpy(&items[i],&item,sizeof(struct item)); i++; } diff --git a/src/common/grfio.c b/src/common/grfio.c index d226fb158..e95163569 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -645,6 +645,7 @@ static int grfio_entryread(const char *grfname, int gentry) aFree(rBuf); entrys = getlong(grf_header+0x26) - 7; + Assert_retr(4, entrys >= 0); // Get an entry for (entry = 0, ofs = 0; entry < entrys; ++entry) { diff --git a/src/map/battle.c b/src/map/battle.c index 6573ca703..603db4738 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -3872,7 +3872,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * short tdef = status->get_total_def(target); short tmdef = status->get_total_mdef(target); int targetVit = min(120, status_get_vit(target)); - short totaldef = (tmdef + tdef - ((uint64)(tmdef + tdef) >> 32)) >> 1; + short totaldef = (tmdef + tdef - ((uint64)(tmdef + tdef) >> 32)) >> 1; // FIXME: What's the >> 32 supposed to do here? tmdef and tdef are both 16-bit... matk = battle->calc_magic_attack(src, target, skill_id, skill_lv, mflag).damage; atk = battle->calc_base_damage(src, target, skill_id, skill_lv, nk, false, s_ele, ELE_NEUTRAL, EQI_HAND_R, (sc && sc->data[SC_MAXIMIZEPOWER]?1:0)|(sc && sc->data[SC_WEAPONPERFECT]?8:0), md.flag); @@ -3979,7 +3979,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * case RA_CLUSTERBOMB: case RA_FIRINGTRAP: case RA_ICEBOUNDTRAP: - md.damage = skill_lv * sstatus->dex + sstatus->int_ * 5 ; + md.damage = (int64)skill_lv * sstatus->dex + sstatus->int_ * 5 ; RE_LVL_TMDMOD(); if(sd) { @@ -3993,7 +3993,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * break; case WM_SOUND_OF_DESTRUCTION: - md.damage = 1000 * skill_lv + sstatus->int_ * (sd ? pc->checkskill(sd,WM_LESSON) : 10); + md.damage = 1000 * (int64)skill_lv + sstatus->int_ * (sd ? pc->checkskill(sd,WM_LESSON) : 10); md.damage += md.damage * 10 * battle->calc_chorusbonus(sd) / 100; break; /** @@ -4356,6 +4356,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list case NJ_SYURIKEN: case KO_BAKURETSU: flag.distinct = 1; + /* Fall through */ case NJ_KUNAI: case HW_MAGICCRASHER: flag.tdef = 1; @@ -5035,7 +5036,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list } break; case SR_FALLENEMPIRE:// [(Target Size value + Skill Level - 1) x Caster STR] + [(Target current weight x Caster DEX / 120)] - ATK_ADD( ((tstatus->size+1)*2 + skill_lv - 1) * sstatus->str); + ATK_ADD( ((tstatus->size+1)*2 + (int64)skill_lv - 1) * sstatus->str); if( tsd && tsd->weight ){ ATK_ADD( (tsd->weight/10) * sstatus->dex / 120 ); }else{ diff --git a/src/map/channel.c b/src/map/channel.c index 4331f6767..58ff98c2b 100644 --- a/src/map/channel.c +++ b/src/map/channel.c @@ -482,7 +482,7 @@ void channel_irc_join(struct map_session_data *sd) struct channel_data *chan = ircbot->channel; if (sd->state.autotrade || sd->state.standalone) return; - if (!channel->config->irc_name) + if (channel->config->irc_name[0] == '\0') return; if (chan) channel->join(chan, sd, NULL, false); diff --git a/src/map/elemental.c b/src/map/elemental.c index a21c128b0..dd97e1970 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -442,9 +442,9 @@ int elemental_action(struct elemental_data *ed, struct block_list *bl, int64 tic ed->ud.skill_lv = skill_lv; if( skill->get_inf(skill_id) & INF_GROUND_SKILL ) - ed->ud.skilltimer = timer->add( tick+status->get_speed(&ed->bl)*walk_dist, skill->castend_pos, ed->bl.id, 0 ); + ed->ud.skilltimer = timer->add(tick+(int64)status->get_speed(&ed->bl)*walk_dist, skill->castend_pos, ed->bl.id, 0); else - ed->ud.skilltimer = timer->add( tick+status->get_speed(&ed->bl)*walk_dist, skill->castend_id, ed->bl.id, 0 ); + ed->ud.skilltimer = timer->add(tick+(int64)status->get_speed(&ed->bl)*walk_dist, skill->castend_id, ed->bl.id, 0); } return 1; diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 51686d3aa..6bbe1eb20 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -729,7 +729,7 @@ bool homunculus_create(struct map_session_data *sd, struct s_homunculus *hom) { nullpo_retr(false, sd); - Assert((sd->status.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd); + Assert_retr(false, sd->status.hom_id == 0 || sd->hd == 0 || sd->hd->master == sd); i = homun->db_search(hom->class_,HOMUNCULUS_CLASS); if(i < 0) { diff --git a/src/map/intif.c b/src/map/intif.c index 50857baa8..7a860049a 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -130,7 +130,7 @@ int intif_rename(struct map_session_data *sd, int type, char *name) // GM Send a message int intif_broadcast(const char* mes, size_t len, int type) { - int lp = (type|BC_COLOR_MASK) ? 4 : 0; + int lp = (type&BC_COLOR_MASK) ? 4 : 0; // Send to the local players clif->broadcast(NULL, mes, len, type, ALL_CLIENT); @@ -149,9 +149,9 @@ int intif_broadcast(const char* mes, size_t len, int type) WFIFOW(inter_fd,10) = 0; // fontSize not used with standard broadcast WFIFOW(inter_fd,12) = 0; // fontAlign not used with standard broadcast WFIFOW(inter_fd,14) = 0; // fontY not used with standard broadcast - if( type|BC_BLUE ) + if (type&BC_BLUE) WFIFOL(inter_fd,16) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow. - else if( type|BC_WOE ) + else if (type&BC_WOE) WFIFOL(inter_fd,16) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'. memcpy(WFIFOP(inter_fd,16 + lp), mes, len); WFIFOSET(inter_fd, WFIFOW(inter_fd,2)); diff --git a/src/map/npc.c b/src/map/npc.c index 996cd4fda..1721e3db3 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -62,24 +62,27 @@ static struct view_data npc_viewdb2[MAX_NPC_CLASS2_END-MAX_NPC_CLASS2_START]; /* for speedup */ unsigned int npc_market_qty[MAX_INVENTORY]; -static struct script_event_s -{ +static struct script_event_s { //Holds pointers to the commonly executed scripts for speedup. [Skotlex] struct event_data *event[UCHAR_MAX]; const char *event_name[UCHAR_MAX]; uint8 event_count; } script_event[NPCE_MAX]; +/** + * Returns the viewdata for normal npc classes. + * @param class_ The NPC class ID. + * @return The viewdata, or NULL if the ID is invalid. + */ struct view_data* npc_get_viewdata(int class_) { - //Returns the viewdata for normal npc classes. - if( class_ == INVISIBLE_CLASS ) + if (class_ == INVISIBLE_CLASS) return &npc_viewdb[0]; - if (npc->db_checkid(class_) || class_ == WARP_CLASS){ - if( class_ > MAX_NPC_CLASS2_START ){ - return &npc_viewdb2[class_-MAX_NPC_CLASS2_START]; - }else{ + if (npc->db_checkid(class_) || class_ == WARP_CLASS) { + if (class_ < MAX_NPC_CLASS2_START) { return &npc_viewdb[class_]; + } else { + return &npc_viewdb2[class_-MAX_NPC_CLASS2_START]; } } return NULL; diff --git a/src/map/pet.c b/src/map/pet.c index b37d3c350..52a8017b4 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -132,7 +132,7 @@ int pet_target_check(struct map_session_data *sd,struct block_list *bl,int type) pd = sd->pd; - Assert((pd->msd == 0) || (pd->msd->pd == pd)); + Assert_ret(pd->msd == 0 || pd->msd->pd == pd); if( bl == NULL || bl->type != BL_MOB || bl->prev == NULL || pd->pet.intimate < battle_config.pet_support_min_friendly @@ -318,8 +318,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) int i=0,interval=0; nullpo_retr(1, sd); - - Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); + Assert_retr(1, sd->status.pet_id == 0 || sd->pd == 0 || sd->pd->msd == sd); if(sd->status.account_id != petinfo->account_id || sd->status.char_id != petinfo->char_id) { sd->status.pet_id = 0; @@ -389,8 +388,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) { nullpo_retr(1, sd); - - Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); + Assert_retr(1, sd->status.pet_id == 0 || sd->pd == 0 || sd->pd->msd == sd); if(sd->status.pet_id && petinfo->incubate == 1) { sd->status.pet_id = 0; @@ -418,7 +416,7 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); clif->send_petstatus(sd); } - Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); + Assert_retr(1, sd->status.pet_id == 0 || sd->pd == 0 || sd->pd->msd == sd); return 0; } @@ -781,10 +779,10 @@ int pet_food(struct map_session_data *sd, struct pet_data *pd) { return 0; } -int pet_randomwalk(struct pet_data *pd, int64 tick) { +int pet_randomwalk(struct pet_data *pd, int64 tick) +{ nullpo_ret(pd); - - Assert((pd->msd == 0) || (pd->msd->pd == pd)); + Assert_ret(pd->msd == 0 || pd->msd->pd == pd); if (DIFF_TICK(pd->next_walktime,tick) < 0 && unit->can_move(&pd->bl)) { const int retrycount=20; diff --git a/src/map/script.c b/src/map/script.c index 898d341ed..bcc3fd710 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -406,7 +406,7 @@ unsigned int calc_hash_ci(const char* p) { /// Looks up string using the provided id. const char* script_get_str(int id) { - Assert( id >= LABEL_START && id < script->str_size ); + Assert_retr(NULL, id >= LABEL_START && id < script->str_size); return script->str_buf+script->str_data[id].str; } @@ -462,7 +462,7 @@ const char *script_casecheck_add_str_sub(struct casecheck_data *ccd, const char int i; for (i = ccd->str_hash[h]; ; i = ccd->str_data[i].next) { const char *s = NULL; - Assert( i >= 0 && i < ccd->str_size ); + Assert_retb(i >= 0 && i < ccd->str_size); s = ccd->str_buf+ccd->str_data[i].str; if (strcasecmp(s,p) == 0) { return s; // string already in list |