summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaruna <haru@dotalux.com>2015-01-01 18:06:10 +0100
committerHaruna <haru@dotalux.com>2015-01-01 18:06:10 +0100
commitff607f15ec14783aed8c0cf2749ac8cbe6d0e7db (patch)
treee121e6c1e25ff47a26090437c937b022d2bfebc6 /src
parentdc6b470e4aaf252cb4f960b8b5585e51da821893 (diff)
parentf70d54001cd1b975db6f4668a6d54dbae7a8ac92 (diff)
downloadhercules-ff607f15ec14783aed8c0cf2749ac8cbe6d0e7db.tar.gz
hercules-ff607f15ec14783aed8c0cf2749ac8cbe6d0e7db.tar.bz2
hercules-ff607f15ec14783aed8c0cf2749ac8cbe6d0e7db.tar.xz
hercules-ff607f15ec14783aed8c0cf2749ac8cbe6d0e7db.zip
Merge pull request #425 from 4144/fixes
Different fixes after automatic checks
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c5
-rw-r--r--src/char/inter.c2
-rw-r--r--src/common/HPM.c27
-rw-r--r--src/common/mutex.c2
-rw-r--r--src/common/socket.c14
-rw-r--r--src/common/sysinfo.c2
-rw-r--r--src/common/timer.c1
-rw-r--r--src/common/utils.c2
-rw-r--r--src/login/login.c6
-rw-r--r--src/map/HPMmap.c8
-rw-r--r--src/map/atcommand.c19
-rw-r--r--src/map/battle.c4
-rw-r--r--src/map/battleground.c11
-rw-r--r--src/map/clif.c5
-rw-r--r--src/map/guild.c28
-rw-r--r--src/map/instance.c38
-rw-r--r--src/map/irc-bot.c3
-rw-r--r--src/map/itemdb.c82
-rw-r--r--src/map/log.c6
-rw-r--r--src/map/map.c68
-rw-r--r--src/map/mob.c16
-rw-r--r--src/map/npc.c24
-rw-r--r--src/map/party.c31
-rw-r--r--src/map/pc.c8
-rw-r--r--src/map/script.c6
-rw-r--r--src/map/skill.c3
-rw-r--r--src/map/status.c19
-rw-r--r--src/map/unit.c28
28 files changed, 261 insertions, 207 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 698832bfb..f63f1c66d 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -793,7 +793,7 @@ int char_memitemdata_to_sql(const struct item items[], int max, int id, int tabl
StrBuf->Clear(&buf);
StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `bound`='%d'",
tablename, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].bound);
- for( j = 0; j < MAX_SLOTS; ++j )for( j = 0; j < MAX_SLOTS; ++j )
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]);
StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id);
@@ -2209,8 +2209,7 @@ static void char_auth_ok(int fd, struct char_session_data *sd)
mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2);
if (character->waiting_disconnect == INVALID_TIMER)
character->waiting_disconnect = timer->add(timer->gettick()+20000, chr->waiting_disconnect, character->account_id, 0);
- if (character)
- character->pincode_enable = -1;
+ character->pincode_enable = -1;
chr->authfail_fd(fd, 8);
return;
}
diff --git a/src/char/inter.c b/src/char/inter.c
index ab91e25b9..e60da2b4f 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -1342,7 +1342,7 @@ void inter_defaults(void)
inter->init_sql = inter_init_sql;
inter->mapif_init = inter_mapif_init;
inter->check_ttl_wisdata_sub = inter_check_ttl_wisdata_sub;
- inter->check_ttl_wisdata = inter->check_ttl_wisdata;
+ inter->check_ttl_wisdata = inter_check_ttl_wisdata;
inter->check_length = inter_check_length;
inter->parse_frommap = inter_parse_frommap;
inter->final = inter_final;
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 51a595310..92b9702d4 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -844,12 +844,13 @@ void hpm_memdown(void) {
/* this memory is handled outside of the server's memory manager and thus cleared after memory manager goes down */
- for( i = 0; i < HPM->fnamec; i++ ) {
- free(HPM->fnames[i].name);
- }
-
- if( HPM->fnames )
+ if (HPM->fnames)
+ {
+ for( i = 0; i < HPM->fnamec; i++ ) {
+ free(HPM->fnames[i].name);
+ }
free(HPM->fnames);
+ }
}
int hpm_arg_db_clear_sub(DBKey key, DBData *data, va_list args) {
struct HPMArgData *a = DB->data2ptr(data);
@@ -863,19 +864,21 @@ void hpm_final(void) {
HPM->off = true;
- for( i = 0; i < HPM->plugin_count; i++ ) {
- HPM->unload(HPM->plugins[i]);
- }
-
if( HPM->plugins )
+ {
+ for( i = 0; i < HPM->plugin_count; i++ ) {
+ HPM->unload(HPM->plugins[i]);
+ }
aFree(HPM->plugins);
-
- for( i = 0; i < HPM->symbol_count; i++ ) {
- aFree(HPM->symbols[i]);
}
if( HPM->symbols )
+ {
+ for( i = 0; i < HPM->symbol_count; i++ ) {
+ aFree(HPM->symbols[i]);
+ }
aFree(HPM->symbols);
+ }
for( i = 0; i < hpPHP_MAX; i++ ) {
if( HPM->packets[i] )
diff --git a/src/common/mutex.c b/src/common/mutex.c
index 31202d440..7307f5f15 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -94,7 +94,7 @@ void ramutex_lock(ramutex *m) {
bool ramutex_trylock(ramutex *m) {
#ifdef WIN32
- if(TryEnterCriticalSection(&m->hMutex) == TRUE)
+ if(TryEnterCriticalSection(&m->hMutex) != FALSE)
return true;
return false;
diff --git a/src/common/socket.c b/src/common/socket.c
index 09521c312..c0864c9b3 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -633,14 +633,16 @@ static void delete_session(int fd)
aFree(session[fd]->wdata);
if( session[fd]->session_data )
aFree(session[fd]->session_data);
- for(i = 0; i < session[fd]->hdatac; i++) {
- if( session[fd]->hdata[i]->flag.free ) {
- aFree(session[fd]->hdata[i]->data);
- }
- aFree(session[fd]->hdata[i]);
- }
if( session[fd]->hdata )
+ {
+ for(i = 0; i < session[fd]->hdatac; i++) {
+ if( session[fd]->hdata[i]->flag.free ) {
+ aFree(session[fd]->hdata[i]->data);
+ }
+ aFree(session[fd]->hdata[i]);
+ }
aFree(session[fd]->hdata);
+ }
aFree(session[fd]);
session[fd] = NULL;
}
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index 605256100..ee8ff504a 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -594,7 +594,7 @@ void sysinfo_osversion_retrieve(void) {
// Include service pack (if any) and build number.
- if (strlen(osvi.szCSDVersion) > 0) {
+ if (osvi.szCSDVersion[0] != '\0') {
StrBuf->Printf(&buf, " %s", osvi.szCSDVersion);
}
diff --git a/src/common/timer.c b/src/common/timer.c
index f2bfa98b3..45dbb9f50 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -260,6 +260,7 @@ static int acquire_timer(void) {
// check available space
if( tid >= timer_data_num )
+ // possible timer_data null pointer
for (tid = timer_data_num; tid < timer_data_max && timer_data[tid].type; tid++);
if (tid >= timer_data_num && tid >= timer_data_max)
{// expand timer array
diff --git a/src/common/utils.c b/src/common/utils.c
index d73aab066..f4e261222 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -134,7 +134,7 @@ void findfile(const char *p, const char *pat, void (func)(const char*))
sprintf(tmppath,"%s%c%s",path,PATHSEP,FindFileData.cFileName);
- if (FindFileData.cFileName && strstr(FindFileData.cFileName, pattern)) {
+ if (strstr(FindFileData.cFileName, pattern)) {
func( tmppath );
}
diff --git a/src/login/login.c b/src/login/login.c
index c006d9c45..e5f565644 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -409,7 +409,7 @@ void login_fromchar_account(int fd, int account_id, struct mmo_account *acc)
char_slots = acc->char_slots;
safestrncpy(pincode, acc->pincode, sizeof(pincode));
safestrncpy(birthdate, acc->birthdate, sizeof(birthdate));
- if( strlen(pincode) == 0 )
+ if (pincode[0] == '\0')
memset(pincode,'\0',sizeof(pincode));
safestrncpy((char*)WFIFOP(fd,6), email, 40);
@@ -1097,9 +1097,9 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
// Account creation with _M/_F
if( login_config.new_account_flag ) {
- if( len > 2 && strnlen(sd->passwd, NAME_LENGTH) > 0 && // valid user and password lengths
+ if (len > 2 && sd->passwd[0] != '\0' && // valid user and password lengths
sd->passwdenc == 0 && // unencoded password
- sd->userid[len-2] == '_' && memchr("FfMm", sd->userid[len-1], 4) ) // _M/_F suffix
+ sd->userid[len-2] == '_' && memchr("FfMm", sd->userid[len-1], 4)) // _M/_F suffix
{
int result;
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c
index f1cdec538..cb4e79108 100644
--- a/src/map/HPMmap.c
+++ b/src/map/HPMmap.c
@@ -181,11 +181,13 @@ void HPM_map_do_final(void) {
* why is pcg->HPM being cleared here? because PCG's do_final is not final,
* is used on reload, and would thus cause plugin-provided permissions to go away
**/
- for( i = 0; i < pcg->HPMpermissions_count; i++ ) {
- aFree(pcg->HPMpermissions[i].name);
- }
if( pcg->HPMpermissions )
+ {
+ for( i = 0; i < pcg->HPMpermissions_count; i++ ) {
+ aFree(pcg->HPMpermissions[i].name);
+ }
aFree(pcg->HPMpermissions);
+ }
HPM->datacheck_final();
}
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 330fe6284..6f97141b2 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1315,9 +1315,7 @@ ACMD(baselevelup)
{
int level=0, i=0, status_point=0;
- level = atoi(message);
-
- if (!message || !*message || !level) {
+ if (!message || !*message || !(level = atoi(message))) {
clif->message(fd, msg_txt(986)); // Please enter a level adjustment (usage: @lvup/@blevel/@baselvlup <number of levels>).
return false;
}
@@ -1376,9 +1374,7 @@ ACMD(joblevelup)
{
int level=0;
- level = atoi(message);
-
- if (!message || !*message || !level) {
+ if (!message || !*message || !(level = atoi(message))) {
clif->message(fd, msg_txt(987)); // Please enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup <number of levels>).
return false;
}
@@ -6679,7 +6675,7 @@ ACMD(showmobs)
return false;
}
- if(mob_id == atoi(mob_name) && mob->db(mob_id)->jname)
+ if(mob_id == atoi(mob_name))
strcpy(mob_name,mob->db(mob_id)->jname); // --ja--
//strcpy(mob_name,mob_db(mob_id)->name); // --en--
@@ -6803,7 +6799,7 @@ ACMD(hommutate) {
m_class = homun->class2type(sd->hd->homunculus.class_);
m_id = homun->class2type(homun_id);
- if( m_class != HT_INVALID && m_id != HT_INVALID && m_class == HT_EVO && m_id == HT_S && sd->hd->homunculus.level >= 99 ) {
+ if (m_class == HT_EVO && m_id == HT_S && sd->hd->homunculus.level >= 99) {
homun->mutate(sd->hd, homun_id);
} else {
clif->emotion(&sd->hd->bl, E_SWT);
@@ -8570,10 +8566,12 @@ ACMD(cart) {
sd->status.skill[idx].flag = (x)?1:0; \
} while(0)
- int val = atoi(message);
+ int val;
bool need_skill = pc->checkskill(sd, MC_PUSHCART) ? false : true;
unsigned int index = skill->get_index(MC_PUSHCART);
+ if (message)
+ val = atoi(message);
if( !message || !*message || val < 0 || val > MAX_CARTS ) {
sprintf(atcmd_output, msg_txt(1390),command,MAX_CARTS); // Unknown Cart (usage: %s <0-%d>).
clif->message(fd, atcmd_output);
@@ -8742,10 +8740,11 @@ ACMD(channel) {
if (strcmpi(subcmd,"create") == 0 && (clif->hChSys->allow_user_channel_creation || pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN))) {
// sub1 = channel name; sub2 = password; sub3 = unused
+ size_t len = strlen(sub1);
if (sub1[0] != '#') {
clif->message(fd, msg_txt(1405));// Channel name must start with a '#'
return false;
- } else if (strlen(sub1) < 3 || strlen(sub1) > HCHSYS_NAME_LENGTH) {
+ } else if (len < 3 || len > HCHSYS_NAME_LENGTH) {
sprintf(atcmd_output, msg_txt(1406), HCHSYS_NAME_LENGTH);// Channel length must be between 3 and %d
clif->message(fd, atcmd_output);
return false;
diff --git a/src/map/battle.c b/src/map/battle.c
index ddad2c705..86134db52 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -348,7 +348,7 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d
struct skill_unit_group *sg;
struct block_list *sgsrc;
- if( !su || !su->alive
+ if(!su->alive
|| (sg = su->group) == NULL || sg->val3 == -1
|| (sgsrc = map->id2bl(sg->src_id)) == NULL || status->isdead(sgsrc)
)
@@ -2594,6 +2594,8 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
nullpo_ret(bl);
+ // need check src for null pointer?
+
if( !damage )
return 0;
if( battle_config.ksprotection && mob->ksprotected(src, bl) )
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 190f7886d..94a6f0626 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -860,13 +860,14 @@ void do_final_battleground(void) {
db_destroy(bg->team_db);
- for( i = 0; i < bg->arenas; i++ ) {
- if( bg->arena[i] )
- aFree(bg->arena[i]);
- }
-
if( bg->arena )
+ {
+ for( i = 0; i < bg->arenas; i++ ) {
+ if( bg->arena[i] )
+ aFree(bg->arena[i]);
+ }
aFree(bg->arena);
+ }
}
void battleground_defaults(void) {
bg = &bg_s;
diff --git a/src/map/clif.c b/src/map/clif.c
index d7b10f2f4..9309ad7b3 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -4749,6 +4749,7 @@ int clif_outsight(struct block_list *bl,va_list ap)
TBL_PC *sd, *tsd;
tbl=va_arg(ap,struct block_list*);
if(bl == tbl) return 0;
+ // bl can be null pointer? and after if BL_PC, sd will be null pointer too
sd = BL_CAST(BL_PC, bl);
tsd = BL_CAST(BL_PC, tbl);
@@ -14495,8 +14496,8 @@ void clif_ranking_pk(struct map_session_data* sd) {
WFIFOHEAD(fd,packet_len(0x238));
WFIFOW(fd,0) = 0x238;
- for(i=0;i<10;i++){
- memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
+ for (i = 0; i < 10;i ++) {
+ strncpy((char*)WFIFOP(fd, i * 24 + 2), "Unknown", NAME_LENGTH);
WFIFOL(fd,i*4+242) = 0;
}
WFIFOSET(fd, packet_len(0x238));
diff --git a/src/map/guild.c b/src/map/guild.c
index d46da60a3..3d5a0e09e 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -1785,14 +1785,16 @@ int guild_broken(int guild_id,int flag)
if( g->instance )
aFree(g->instance);
- for( i = 0; i < g->hdatac; i++ ) {
- if( g->hdata[i]->flag.free ) {
- aFree(g->hdata[i]->data);
- }
- aFree(g->hdata[i]);
- }
if( g->hdata )
+ {
+ for( i = 0; i < g->hdatac; i++ ) {
+ if( g->hdata[i]->flag.free ) {
+ aFree(g->hdata[i]->data);
+ }
+ aFree(g->hdata[i]);
+ }
aFree(g->hdata);
+ }
idb_remove(guild->db,guild_id);
return 0;
@@ -2279,14 +2281,16 @@ void do_final_guild(void) {
aFree(g->instance);
g->instance = NULL;
}
- for( i = 0; i < g->hdatac; i++ ) {
- if( g->hdata[i]->flag.free ) {
- aFree(g->hdata[i]->data);
- }
- aFree(g->hdata[i]);
- }
if( g->hdata )
+ {
+ for( i = 0; i < g->hdatac; i++ ) {
+ if( g->hdata[i]->flag.free ) {
+ aFree(g->hdata[i]->data);
+ }
+ aFree(g->hdata[i]);
+ }
aFree(g->hdata);
+ }
}
dbi_destroy(iter);
diff --git a/src/map/instance.c b/src/map/instance.c
index 4140973b1..96bdcc053 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -430,28 +430,25 @@ void instance_del_map(int16 m) {
aFree(map->list[m].block);
aFree(map->list[m].block_mob);
- if( map->list[m].unit_count ) {
+ if (map->list[m].unit_count && map->list[m].units) {
for(i = 0; i < map->list[m].unit_count; i++) {
aFree(map->list[m].units[i]);
}
- if( map->list[m].units )
- aFree(map->list[m].units);
+ aFree(map->list[m].units);
}
- if( map->list[m].skill_count ) {
+ if (map->list[m].skill_count && map->list[m].skills) {
for(i = 0; i < map->list[m].skill_count; i++) {
aFree(map->list[m].skills[i]);
}
- if( map->list[m].skills )
- aFree(map->list[m].skills);
+ aFree(map->list[m].skills);
}
- if( map->list[m].zone_mf_count ) {
+ if (map->list[m].zone_mf_count && map->list[m].zone_mf) {
for(i = 0; i < map->list[m].zone_mf_count; i++) {
aFree(map->list[m].zone_mf[i]);
}
- if( map->list[m].zone_mf )
- aFree(map->list[m].zone_mf);
+ aFree(map->list[m].zone_mf);
}
if( map->list[m].qi_data )
@@ -548,9 +545,12 @@ void instance_destroy(int instance_id) {
iptr[j] = -1;
}
- while( instance->list[instance_id].num_map && last != instance->list[instance_id].map[0] ) { // Remove all maps from instance
- last = instance->list[instance_id].map[0];
- instance->del_map( instance->list[instance_id].map[0] );
+ if (instance->list[instance_id].map)
+ {
+ while( instance->list[instance_id].num_map && last != instance->list[instance_id].map[0] ) { // Remove all maps from instance
+ last = instance->list[instance_id].map[0];
+ instance->del_map( instance->list[instance_id].map[0] );
+ }
}
if( instance->list[instance_id].regs.vars )
@@ -572,14 +572,16 @@ void instance_destroy(int instance_id) {
instance->list[instance_id].state = INSTANCE_FREE;
instance->list[instance_id].num_map = 0;
- for( j = 0; j < instance->list[instance_id].hdatac; j++ ) {
- if( instance->list[instance_id].hdata[j]->flag.free ) {
- aFree(instance->list[instance_id].hdata[j]->data);
+ if (instance->list[instance_id].hdata)
+ {
+ for( j = 0; j < instance->list[instance_id].hdatac; j++ ) {
+ if( instance->list[instance_id].hdata[j]->flag.free ) {
+ aFree(instance->list[instance_id].hdata[j]->data);
+ }
+ aFree(instance->list[instance_id].hdata[j]);
}
- aFree(instance->list[instance_id].hdata[j]);
- }
- if( instance->list[instance_id].hdata )
aFree(instance->list[instance_id].hdata);
+ }
instance->list[instance_id].hdata = NULL;
instance->list[instance_id].hdatac = 0;
diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c
index 8b4991c20..bd35a9867 100644
--- a/src/map/irc-bot.c
+++ b/src/map/irc-bot.c
@@ -281,7 +281,8 @@ void irc_privmsg_ctcp(int fd, char *cmd, char *source, char *target, char *msg)
* @see irc_parse_sub
*/
void irc_privmsg(int fd, char *cmd, char *source, char *target, char *msg) {
- if( msg && *msg == '\001' && strlen(msg) > 2 && msg[strlen(msg)-1] == '\001' ) {
+ size_t len = msg ? strlen(msg) : 0;
+ if (msg && *msg == '\001' && len > 2 && msg[len - 1] == '\001') {
// CTCP
char command[IRC_MESSAGE_LENGTH], message[IRC_MESSAGE_LENGTH];
command[0] = message[0] = '\0';
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 19cc02d21..8b6dfba63 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -1427,7 +1427,7 @@ int itemdb_validate_entry(struct item_data *entry, int n, const char *source) {
entry->type = IT_ETC;
}
- if (entry->flag.trade_restriction < 0 || entry->flag.trade_restriction > ITR_ALL) {
+ if (entry->flag.trade_restriction > ITR_ALL) {
ShowWarning("itemdb_validate_entry: Invalid trade restriction flag 0x%x for item %d (%s) in '%s', defaulting to none.\n",
entry->flag.trade_restriction, entry->nameid, entry->jname, source);
entry->flag.trade_restriction = ITR_NONE;
@@ -2106,14 +2106,16 @@ void destroy_item_data(struct item_data* self, int free_self)
script->free_code(self->unequip_script);
if( self->combos )
aFree(self->combos);
- for (v = 0; v < self->hdatac; v++ ) {
- if (self->hdata[v]->flag.free ) {
- aFree(self->hdata[v]->data);
- }
- aFree(self->hdata[v]);
- }
if (self->hdata)
+ {
+ for (v = 0; v < self->hdatac; v++ ) {
+ if (self->hdata[v]->flag.free ) {
+ aFree(self->hdata[v]->data);
+ }
+ aFree(self->hdata[v]);
+ }
aFree(self->hdata);
+ }
#if defined(DEBUG)
// trash item
memset(self, 0xDD, sizeof(struct item_data));
@@ -2143,52 +2145,58 @@ void itemdb_clear(bool total) {
itemdb->destroy_item_data(itemdb->array[i], 1);
}
- for( i = 0; i < itemdb->group_count; i++ ) {
- if( itemdb->groups[i].nameid )
- aFree(itemdb->groups[i].nameid);
- }
-
if( itemdb->groups )
+ {
+ for( i = 0; i < itemdb->group_count; i++ ) {
+ if( itemdb->groups[i].nameid )
+ aFree(itemdb->groups[i].nameid);
+ }
aFree(itemdb->groups);
-
+ }
+
itemdb->groups = NULL;
itemdb->group_count = 0;
- for( i = 0; i < itemdb->chain_count; i++ ) {
- if( itemdb->chains[i].items )
- aFree(itemdb->chains[i].items);
- }
-
if( itemdb->chains )
+ {
+ for( i = 0; i < itemdb->chain_count; i++ ) {
+ if( itemdb->chains[i].items )
+ aFree(itemdb->chains[i].items);
+ }
aFree(itemdb->chains);
-
+ }
+
itemdb->chains = NULL;
itemdb->chain_count = 0;
- for( i = 0; i < itemdb->package_count; i++ ) {
- int c;
- for( c = 0; c < itemdb->packages[i].random_qty; c++ )
- aFree(itemdb->packages[i].random_groups[c].random_list);
- if( itemdb->packages[i].random_groups )
- aFree(itemdb->packages[i].random_groups);
- if( itemdb->packages[i].must_items )
- aFree(itemdb->packages[i].must_items);
- }
-
if( itemdb->packages )
+ {
+ for( i = 0; i < itemdb->package_count; i++ ) {
+ int c;
+ if (itemdb->packages[i].random_groups)
+ {
+ for( c = 0; c < itemdb->packages[i].random_qty; c++ )
+ aFree(itemdb->packages[i].random_groups[c].random_list);
+ aFree(itemdb->packages[i].random_groups);
+ }
+ if( itemdb->packages[i].must_items )
+ aFree(itemdb->packages[i].must_items);
+ }
aFree(itemdb->packages);
-
- itemdb->packages = NULL;
+ itemdb->packages = NULL;
+ }
itemdb->package_count = 0;
- for(i = 0; i < itemdb->combo_count; i++) {
- if( itemdb->combos[i]->script ) // Check if script was loaded
- script->free_code(itemdb->combos[i]->script);
- aFree(itemdb->combos[i]);
- }
if( itemdb->combos )
+ {
+ for(i = 0; i < itemdb->combo_count; i++) {
+ if( itemdb->combos[i]->script ) // Check if script was loaded
+ script->free_code(itemdb->combos[i]->script);
+ aFree(itemdb->combos[i]);
+ }
aFree(itemdb->combos);
-
+ }
+
itemdb->combos = NULL;
itemdb->combo_count = 0;
diff --git a/src/map/log.c b/src/map/log.c
index 92956fa67..f18efbfb7 100644
--- a/src/map/log.c
+++ b/src/map/log.c
@@ -134,7 +134,7 @@ void log_pick_sub_sql(int id, int16 m, e_log_pick_type type, int amount, struct
LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`) "
"VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')",
logs->config.log_pick, id, logs->picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3],
- map->list[m].name?map->list[m].name:"", itm->unique_id)
+ map->list[m].name, itm->unique_id)
) {
Sql_ShowDebug(logs->mysql_handle);
return;
@@ -151,7 +151,7 @@ void log_pick_sub_txt(int id, int16 m, e_log_pick_type type, int amount, struct
strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s,'%"PRIu64"'\n",
timestring, id, logs->picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3],
- map->list[m].name?map->list[m].name:"", itm->unique_id);
+ map->list[m].name, itm->unique_id);
fclose(logfp);
}
/// logs item transactions (generic)
@@ -368,7 +368,7 @@ void log_sql_init(void) {
exit(EXIT_FAILURE);
ShowStatus(""CL_WHITE"[SQL]"CL_RESET": Successfully '"CL_GREEN"connected"CL_RESET"' to Database '"CL_WHITE"%s"CL_RESET"'.\n", logs->db_name);
- if( strlen(map->default_codepage) > 0 )
+ if (map->default_codepage[0] != '\0')
if ( SQL_ERROR == SQL->SetEncoding(logs->mysql_handle, map->default_codepage) )
Sql_ShowDebug(logs->mysql_handle);
}
diff --git a/src/map/map.c b/src/map/map.c
index 25d7ce692..2bebd3c55 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -3158,10 +3158,10 @@ void map_clean(int i) {
}
if( map->list[i].unit_count ) {
- for(v = 0; v < map->list[i].unit_count; v++) {
- aFree(map->list[i].units[v]);
- }
if( map->list[i].units ) {
+ for(v = 0; v < map->list[i].unit_count; v++) {
+ aFree(map->list[i].units[v]);
+ }
aFree(map->list[i].units);
map->list[i].units = NULL;
}
@@ -3169,10 +3169,10 @@ void map_clean(int i) {
}
if( map->list[i].skill_count ) {
- for(v = 0; v < map->list[i].skill_count; v++) {
- aFree(map->list[i].skills[v]);
- }
if( map->list[i].skills ) {
+ for(v = 0; v < map->list[i].skill_count; v++) {
+ aFree(map->list[i].skills[v]);
+ }
aFree(map->list[i].skills);
map->list[i].skills = NULL;
}
@@ -3180,10 +3180,10 @@ void map_clean(int i) {
}
if( map->list[i].zone_mf_count ) {
- for(v = 0; v < map->list[i].zone_mf_count; v++) {
- aFree(map->list[i].zone_mf[v]);
- }
if( map->list[i].zone_mf ) {
+ for(v = 0; v < map->list[i].zone_mf_count; v++) {
+ aFree(map->list[i].zone_mf[v]);
+ }
aFree(map->list[i].zone_mf);
map->list[i].zone_mf = NULL;
}
@@ -3211,10 +3211,10 @@ void do_final_maps(void) {
}
if( map->list[i].unit_count ) {
- for(v = 0; v < map->list[i].unit_count; v++) {
- aFree(map->list[i].units[v]);
- }
if( map->list[i].units ) {
+ for(v = 0; v < map->list[i].unit_count; v++) {
+ aFree(map->list[i].units[v]);
+ }
aFree(map->list[i].units);
map->list[i].units = NULL;
}
@@ -3222,10 +3222,10 @@ void do_final_maps(void) {
}
if( map->list[i].skill_count ) {
- for(v = 0; v < map->list[i].skill_count; v++) {
- aFree(map->list[i].skills[v]);
- }
if( map->list[i].skills ) {
+ for(v = 0; v < map->list[i].skill_count; v++) {
+ aFree(map->list[i].skills[v]);
+ }
aFree(map->list[i].skills);
map->list[i].skills = NULL;
}
@@ -3233,10 +3233,10 @@ void do_final_maps(void) {
}
if( map->list[i].zone_mf_count ) {
- for(v = 0; v < map->list[i].zone_mf_count; v++) {
- aFree(map->list[i].zone_mf[v]);
- }
if( map->list[i].zone_mf ) {
+ for(v = 0; v < map->list[i].zone_mf_count; v++) {
+ aFree(map->list[i].zone_mf[v]);
+ }
aFree(map->list[i].zone_mf);
map->list[i].zone_mf = NULL;
}
@@ -3255,14 +3255,16 @@ void do_final_maps(void) {
if( map->list[i].qi_data )
aFree(map->list[i].qi_data);
- for( v = 0; v < map->list[i].hdatac; v++ ) {
- if( map->list[i].hdata[v]->flag.free ) {
- aFree(map->list[i].hdata[v]->data);
- }
- aFree(map->list[i].hdata[v]);
- }
if( map->list[i].hdata )
+ {
+ for( v = 0; v < map->list[i].hdatac; v++ ) {
+ if( map->list[i].hdata[v]->flag.free ) {
+ aFree(map->list[i].hdata[v]->data);
+ }
+ aFree(map->list[i].hdata[v]);
+ }
aFree(map->list[i].hdata);
+ }
}
map->zone_db_clear();
@@ -3808,7 +3810,7 @@ int map_sql_init(void)
exit(EXIT_FAILURE);
ShowStatus("connect success! (Map Server Connection)\n");
- if( strlen(map->default_codepage) > 0 )
+ if (map->default_codepage[0] != '\0')
if ( SQL_ERROR == SQL->SetEncoding(map->mysql_handle, map->default_codepage) )
Sql_ShowDebug(map->mysql_handle);
@@ -5561,7 +5563,7 @@ CPCMD(gm_position) {
return;
}
- if ( (m = map->mapname2mapid(map_name) <= 0 ) ) {
+ if ((m = map->mapname2mapid(map_name)) <= 0) {
ShowError("gm:info '"CL_WHITE"%s"CL_RESET"' is not a known map\n",map_name);
return;
}
@@ -5927,13 +5929,15 @@ int do_init(int argc, char *argv[])
vending->init(minimal);
if (scriptcheck) {
- bool failed = load_extras_count > 0 ? false : true;
- for (i = 0; i < load_extras_count; i++) {
- if (npc->parsesrcfile(load_extras[i], false) != EXIT_SUCCESS)
- failed = true;
+ if (load_extras) {
+ bool failed = load_extras_count > 0 ? false : true;
+ for (i = 0; i < load_extras_count; i++) {
+ if (npc->parsesrcfile(load_extras[i], false) != EXIT_SUCCESS)
+ failed = true;
+ }
+ if (failed)
+ exit(EXIT_FAILURE);
}
- if (failed)
- exit(EXIT_FAILURE);
exit(EXIT_SUCCESS);
}
if (load_extras) {
diff --git a/src/map/mob.c b/src/map/mob.c
index 4db8cb2f6..ce5854928 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -4324,7 +4324,7 @@ bool mob_parse_row_mobskilldb(char** str, int columns, int current)
if( strcmp(str[1],"clear")==0 ){
if (mob_id < 0)
return false;
- memset(mob->db_data[mob_id]->skill,0,sizeof(struct mob_skill));
+ memset(mob->db_data[mob_id]->skill,0,sizeof(struct mob_skill) * MAX_MOBSKILL);
mob->db_data[mob_id]->maxskill=0;
return true;
}
@@ -4716,14 +4716,16 @@ void mob_destroy_mob_db(int index)
{
struct mob_db *data = mob->db_data[index];
int v;
- for (v = 0; v < data->hdatac; v++ ) {
- if (data->hdata[v]->flag.free ) {
- aFree(data->hdata[v]->data);
- }
- aFree(data->hdata[v]);
- }
if (data->hdata)
+ {
+ for (v = 0; v < data->hdatac; v++ ) {
+ if (data->hdata[v]->flag.free ) {
+ aFree(data->hdata[v]->data);
+ }
+ aFree(data->hdata[v]);
+ }
aFree(data->hdata);
+ }
aFree(data);
mob->db_data[index] = NULL;
}
diff --git a/src/map/npc.c b/src/map/npc.c
index 6762684af..04df22f2d 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2314,16 +2314,18 @@ int npc_unload(struct npc_data* nd, bool single) {
aFree(nd->ud);
nd->ud = NULL;
}
-
- for( i = 0; i < nd->hdatac; i++ ) {
- if( nd->hdata[i]->flag.free ) {
- aFree(nd->hdata[i]->data);
- }
- aFree(nd->hdata[i]);
- }
+
if( nd->hdata )
+ {
+ for( i = 0; i < nd->hdatac; i++ ) {
+ if( nd->hdata[i]->flag.free ) {
+ aFree(nd->hdata[i]->data);
+ }
+ aFree(nd->hdata[i]);
+ }
aFree(nd->hdata);
-
+ }
+
aFree(nd);
return 0;
@@ -3147,7 +3149,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
nd->u.scr.timerid = INVALID_TIMER;
- if( type == SCRIPT && options&NPO_ONINIT ) {
+ if (options&NPO_ONINIT) {
// From npc_parse_script
char evname[EVENT_NAME_LENGTH];
struct event_data *ev;
@@ -3513,13 +3515,13 @@ const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* st
return strchr(start,'\n');// skip and continue
}
- if( (mobspawn.state.size < 0 || mobspawn.state.size > 2) && size != -1 ) {
+ if (mobspawn.state.size > 2 && size != -1) {
ShowError("npc_parse_mob: Invalid size number %d for mob ID %d in file '%s', line '%d'.\n", mobspawn.state.size, class_, filepath, strline(buffer, start - buffer));
if (retval) *retval = EXIT_FAILURE;
return strchr(start, '\n');
}
- if( (mobspawn.state.ai < 0 || mobspawn.state.ai > 4) && ai != -1 ) {
+ if (mobspawn.state.ai > 4 && ai != -1) {
ShowError("npc_parse_mob: Invalid ai %d for mob ID %d in file '%s', line '%d'.\n", mobspawn.state.ai, class_, filepath, strline(buffer, start - buffer));
if (retval) *retval = EXIT_FAILURE;
return strchr(start, '\n');
diff --git a/src/map/party.c b/src/map/party.c
index 668251b5d..1df916630 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -103,15 +103,17 @@ int party_db_final(DBKey key, DBData *data, va_list ap) {
if( p->instance )
aFree(p->instance);
-
- for( j = 0; j < p->hdatac; j++ ) {
- if( p->hdata[j]->flag.free ) {
- aFree(p->hdata[j]->data);
+
+ if (p->hdata)
+ {
+ for (j = 0; j < p->hdatac; j++) {
+ if (p->hdata[j]->flag.free) {
+ aFree(p->hdata[j]->data);
+ }
+ aFree(p->hdata[j]);
}
- aFree(p->hdata[j]);
- }
- if( p->hdata )
aFree(p->hdata);
+ }
}
return 0;
@@ -609,15 +611,16 @@ int party_broken(int party_id)
if( p->instance )
aFree(p->instance);
- for( j = 0; j < p->hdatac; j++ ) {
- if( p->hdata[j]->flag.free ) {
- aFree(p->hdata[j]->data);
- }
- aFree(p->hdata[j]);
- }
if( p->hdata )
+ {
+ for( j = 0; j < p->hdatac; j++ ) {
+ if( p->hdata[j]->flag.free ) {
+ aFree(p->hdata[j]->data);
+ }
+ aFree(p->hdata[j]);
+ }
aFree(p->hdata);
-
+ }
idb_remove(party->db,party_id);
return 0;
}
diff --git a/src/map/pc.c b/src/map/pc.c
index e39ddbff2..b8902d753 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1422,6 +1422,7 @@ int pc_calc_skilltree(struct map_session_data *sd)
{ //Enable Bard/Dancer spirit linked skills.
if( sd->status.sex )
{ //Link dancer skills to bard.
+ // i can be < 8?
if( sd->status.skill[i-8].lv < 10 )
continue;
sd->status.skill[i].id = skill->db[i].nameid;
@@ -1430,6 +1431,7 @@ int pc_calc_skilltree(struct map_session_data *sd)
} else { //Link bard skills to dancer.
if( sd->status.skill[i].lv < 10 )
continue;
+ // i can be < 8?
sd->status.skill[i-8].id = skill->db[i-8].nameid;
sd->status.skill[i-8].lv = sd->status.skill[i].lv; // Set the level to the same as the linking skill
sd->status.skill[i-8].flag = SKILL_FLAG_TEMPORARY; // Tag it as a non-savable, non-uppable, bonus skill
@@ -3564,7 +3566,7 @@ int pc_skill(TBL_PC* sd, int id, int level, int flag) {
uint16 index = 0;
nullpo_ret(sd);
- if( !(index = skill->get_index(id)) || skill->db[index].name == NULL) {
+ if (!(index = skill->get_index(id))) {
ShowError("pc_skill: Skill with id %d does not exist in the skill database\n", id);
return 0;
}
@@ -4857,7 +4859,7 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil
//A Rare Steal Global Announce by Lupus
if(md->db->dropitem[i].p<=battle_config.rare_drop_announce) {
char message[128];
- sprintf (message, msg_txt(542), (sd->status.name != NULL)?sd->status.name :"GM", md->db->jname, data->jname, (float)md->db->dropitem[i].p/100);
+ sprintf (message, msg_txt(542), sd->status.name, md->db->jname, data->jname, (float)md->db->dropitem[i].p / 100);
//MSG: "'%s' stole %s's %s (chance: %0.02f%%)"
intif->broadcast(message, strlen(message)+1, BC_DEFAULT);
}
@@ -6913,6 +6915,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
int i=0,j=0;
int64 tick = timer->gettick();
+ nullpo_retr(0, sd);
+
for(j = 0; j < 5; j++) {
if (sd->devotion[j]){
struct map_session_data *devsd = map->id2sd(sd->devotion[j]);
diff --git a/src/map/script.c b/src/map/script.c
index 031dfc21b..7634b6c68 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -767,6 +767,7 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
char null_arg = '\0';
int func;
+ // is need add check for arg null pointer below?
func = script->add_word(p);
if( script->str_data[func].type == C_FUNC ) {
// buildin function
@@ -2593,10 +2594,11 @@ void* get_val2(struct script_state* st, int64 uid, struct reg_db *ref) {
**/
void script_array_ensure_zero(struct script_state *st, struct map_session_data *sd, int64 uid, struct reg_db *ref) {
const char *name = script->get_str(script_getvarid(uid));
+ // is here st can be null pointer and st->rid is wrong?
struct reg_db *src = script->array_src(st, sd ? sd : st->rid ? map->id2sd(st->rid) : NULL, name, ref);
struct script_array *sa = NULL;
bool insert = false;
-
+
if( sd && !st ) /* when sd comes, st isn't available */
insert = true;
else {
@@ -4385,7 +4387,7 @@ void do_final_script(void) {
aFree(script->hq[i].item);
}
}
- if( script->hqis ) {
+ if (script->hqis && script->hqi) {
for( i = 0; i < script->hqis; i++ ) {
if( script->hqi[i].item != NULL )
aFree(script->hqi[i].item);
diff --git a/src/map/skill.c b/src/map/skill.c
index 5eb319c02..a89f61a49 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -1653,7 +1653,7 @@ int skill_onskillusage(struct map_session_data *sd, struct block_list *bl, uint1
sd->state.autocast = 0;
}
- if( sd && sd->autobonus3[0].rate ) {
+ if (sd->autobonus3[0].rate) {
for( i = 0; i < ARRAYLENGTH(sd->autobonus3); i++ ) {
if( rnd()%1000 >= sd->autobonus3[i].rate )
continue;
@@ -16255,6 +16255,7 @@ int skill_unit_timer_sub(DBKey key, DBData *data, va_list ap) {
}
}
+ // useless check for !group ?
//Don't continue if unit or even group is expired and has been deleted.
if( !group || !su->alive )
return 0;
diff --git a/src/map/status.c b/src/map/status.c
index 9cd01f7b3..c0611f97b 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -3093,11 +3093,13 @@ int status_calc_elemental_(struct elemental_data *ed, enum e_status_calc_opt opt
}
int status_calc_npc_(struct npc_data *nd, enum e_status_calc_opt opt) {
- struct status_data *nstatus = &nd->status;
+ struct status_data *nstatus;
if (!nd)
return 0;
+ nstatus = &nd->status;
+
if ( opt&SCO_FIRST ) {
nstatus->hp = 1;
nstatus->sp = 1;
@@ -3646,7 +3648,8 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
if(flag&SCB_MAXHP) {
if( bl->type&BL_PC ) {
st->max_hp = status->base_pc_maxhp(sd,st);
- st->max_hp += bst->max_hp - sd->status.max_hp;
+ if (sd)
+ st->max_hp += bst->max_hp - sd->status.max_hp;
st->max_hp = status->calc_maxhp(bl, sc, st->max_hp);
@@ -3666,7 +3669,8 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
if(flag&SCB_MAXSP) {
if( bl->type&BL_PC ) {
st->max_sp = status->base_pc_maxsp(sd,st);
- st->max_sp += bst->max_sp - sd->status.max_sp;
+ if (sd)
+ st->max_sp += bst->max_sp - sd->status.max_sp;
st->max_sp = status->calc_maxsp(&sd->bl, &sd->sc, st->max_sp);
@@ -7149,7 +7153,8 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t
i = sd->equip_index[EQI_ACC_L];
if( i >= 0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_ARMOR )
pc->unequipitem(sd,i,3); //L-Accessory
- } if( !(sd->bonus.unstripable_equip&EQP_ACC_R) ) {
+ }
+ if( !(sd->bonus.unstripable_equip&EQP_ACC_R) ) {
i = sd->equip_index[EQI_ACC_R];
if( i >= 0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_ARMOR )
pc->unequipitem(sd,i,3); //R-Accessory
@@ -9541,10 +9546,12 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t
if(opt_flag) {
clif->changeoption(bl);
if( sd && opt_flag&0x4 ) {
- clif->changelook(bl,LOOK_BASE,vd->class_);
+ if (vd)
+ clif->changelook(bl,LOOK_BASE,vd->class_);
clif->changelook(bl,LOOK_WEAPON,0);
clif->changelook(bl,LOOK_SHIELD,0);
- clif->changelook(bl,LOOK_CLOTHES_COLOR,vd->cloth_color);
+ if (vd)
+ clif->changelook(bl,LOOK_CLOTHES_COLOR,vd->cloth_color);
}
}
if (calc_flag&SCB_DYE) {
diff --git a/src/map/unit.c b/src/map/unit.c
index a5bd282a9..deb061f78 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2657,14 +2657,16 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
sd->num_quests = sd->avail_quests = 0;
}
- for( k = 0; k < sd->hdatac; k++ ) {
- if( sd->hdata[k]->flag.free ) {
- aFree(sd->hdata[k]->data);
- }
- aFree(sd->hdata[k]);
- }
if( sd->hdata )
+ {
+ for( k = 0; k < sd->hdatac; k++ ) {
+ if( sd->hdata[k]->flag.free ) {
+ aFree(sd->hdata[k]->data);
+ }
+ aFree(sd->hdata[k]);
+ }
aFree(sd->hdata);
+ }
break;
}
case BL_PET:
@@ -2776,14 +2778,16 @@ int unit_free(struct block_list *bl, clr_type clrtype) {
if( md->tomb_nid )
mob->mvptomb_destroy(md);
- for (k = 0; k < md->hdatac; k++) {
- if( md->hdata[k]->flag.free ) {
- aFree(md->hdata[k]->data);
- }
- aFree(md->hdata[k]);
- }
if (md->hdata)
+ {
+ for (k = 0; k < md->hdatac; k++) {
+ if( md->hdata[k]->flag.free ) {
+ aFree(md->hdata[k]->data);
+ }
+ aFree(md->hdata[k]);
+ }
aFree(md->hdata);
+ }
break;
}
case BL_HOM: