summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-12-26 02:28:59 +0100
committerHaru <haru@dotalux.com>2016-05-08 19:53:57 +0200
commit2349b2a1528fe5dc41d930f8dd332df5ba521eb6 (patch)
tree3656a91a896f0ef090606b2b4c9184ad73153a3f /src/map
parent58a7bf46508b7f186704e7efb39576e09f0ab866 (diff)
downloadhercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.tar.gz
hercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.tar.bz2
hercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.tar.xz
hercules-2349b2a1528fe5dc41d930f8dd332df5ba521eb6.zip
Fixed various issues pointed out by cppcheck
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/battle.c5
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/instance.c9
-rw-r--r--src/map/path.c8
-rw-r--r--src/map/pc.c23
-rw-r--r--src/map/script.c54
-rw-r--r--src/map/skill.c8
-rw-r--r--src/map/status.c13
8 files changed, 59 insertions, 63 deletions
diff --git a/src/map/battle.c b/src/map/battle.c
index a7a6f4719..09b99aa05 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -3512,8 +3512,6 @@ int battle_blewcount_bonus(struct map_session_data *sd, uint16 skill_id) {
struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list *target,uint16 skill_id,uint16 skill_lv,int mflag) {
int nk;
short s_ele = 0;
- unsigned int skillratio = 100; //Skill dmg modifiers.
-
struct map_session_data *sd = NULL;
struct status_change *sc;
struct Damage ad;
@@ -3666,6 +3664,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list
ad.damage = status->get_lv(src) * 10 + sstatus->int_;
break;
default: {
+ unsigned int skillratio = 100; //Skill dmg modifiers.
MATK_ADD( status->get_matk(src, 2) );
#ifdef RENEWAL
ad.damage = battle->calc_cardfix(BF_MAGIC, src, target, nk, s_ele, 0, ad.damage, 0, ad.flag);
@@ -4276,7 +4275,6 @@ void battle_calc_misc_attack_unknown(struct block_list *src, struct block_list *
// FIXME: wflag is undocumented
struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list *target,uint16 skill_id,uint16 skill_lv,int wflag)
{
- unsigned int skillratio = 100; //Skill dmg modifiers.
short temp=0;
short s_ele, s_ele_;
int i, nk;
@@ -4775,6 +4773,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list
} //End hit/miss calculation
if (flag.hit && !flag.infdef) { //No need to do the math for plants
+ unsigned int skillratio = 100; //Skill dmg modifiers.
//Hitting attack
//Assuming that 99% of the cases we will not need to check for the flag.rh... we don't.
diff --git a/src/map/clif.c b/src/map/clif.c
index cf742fbf6..9b90b946e 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -14771,7 +14771,6 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
{
int mail_id = RFIFOL(fd,2);
int i;
- bool fail = false;
if( !chrif->isconnected() )
return;
@@ -14795,6 +14794,7 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
struct item_data *data;
unsigned int weight;
+ bool fail = false;
if ((data = itemdb->exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
return;
diff --git a/src/map/instance.c b/src/map/instance.c
index a6700d486..fa2cfec16 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -551,7 +551,7 @@ void instance_destroy(int instance_id) {
struct party_data *p = NULL;
struct guild *g = NULL;
short *iptr = NULL;
- int type, j;
+ int type;
unsigned int now = (unsigned int)time(NULL);
if( !instance->valid(instance_id) )
@@ -596,9 +596,10 @@ void instance_destroy(int instance_id) {
}
if( iptr != NULL ) {
- ARR_FIND(0, *icptr, j, iptr[j] == instance_id);
- if( j != *icptr )
- iptr[j] = -1;
+ int i;
+ ARR_FIND(0, *icptr, i, iptr[i] == instance_id);
+ if (i != *icptr)
+ iptr[i] = -1;
}
if (instance->list[instance_id].map) {
diff --git a/src/map/path.c b/src/map/path.c
index 543497c33..0df9708d8 100644
--- a/src/map/path.c
+++ b/src/map/path.c
@@ -254,7 +254,7 @@ static int add_path(struct node_heap *heap, struct path_node *tp, int16 x, int16
*------------------------------------------*/
bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int flag, cell_chk cell)
{
- register int i, j, x, y, dx, dy;
+ register int i, x, y, dx, dy;
struct map_data *md;
struct walkpath_data s_wpd;
@@ -315,8 +315,7 @@ bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int1
}
return false; // easy path unsuccessful
- }
- else { // !(flag&1)
+ } else { // !(flag&1)
// A* (A-star) pathfinding
// We always use A* for finding walkpaths because it is what game client uses.
// Easy pathfinding cuts corners of non-walkable cells, but client always walks around it.
@@ -331,6 +330,7 @@ bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int1
int xs = md->xs - 1;
int ys = md->ys - 1;
int len = 0;
+ int j;
memset(tp, 0, sizeof(tp));
// Start node
@@ -407,7 +407,7 @@ bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int1
}
for (it = current; it->parent != NULL; it = it->parent, len++);
- if (len > sizeof(wpd->path)) {
+ if (len > (int)sizeof(wpd->path)) {
return false;
}
diff --git a/src/map/pc.c b/src/map/pc.c
index ab1e6ebfc..1c635e5cf 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -11014,18 +11014,18 @@ int pc_readdb(void) {
ShowError("can't read %s\n", line);
return 1;
}
- while(fgets(line, sizeof(line), fp))
- {
+ while (fgets(line, sizeof(line), fp)) {
char *split[10];
int lv,n;
- if(line[0]=='/' && line[1]=='/')
+ if (line[0]=='/' && line[1]=='/')
continue;
- for(j=0,p=line;j<3 && p;j++){
- split[j]=p;
- p=strchr(p,',');
- if(p) *p++=0;
+ for (j = 0, p = line; j < 3 && p != NULL; j++) {
+ split[j] = p;
+ p = strchr(p,',');
+ if (p != NULL)
+ *p++ = 0;
}
- if( j < 2 )
+ if (j < 2)
continue;
lv=atoi(split[0]);
@@ -11037,8 +11037,8 @@ int pc_readdb(void) {
if(line[0]=='/' && line[1]=='/')
continue;
- for ( j = ELE_NEUTRAL, p = line; j<n && j<ELE_MAX && p; j++ ) {
- while(*p==32 && *p>0)
+ for (j = ELE_NEUTRAL, p = line; j < n && j < ELE_MAX && p != NULL; j++) {
+ while (*p == ' ')
p++;
battle->attr_fix_table[lv-1][i][j]=atoi(p);
#ifndef RENEWAL
@@ -11046,7 +11046,8 @@ int pc_readdb(void) {
battle->attr_fix_table[lv-1][i][j] = 0;
#endif
p=strchr(p,',');
- if(p) *p++=0;
+ if (p != NULL)
+ *p++ = 0;
}
i++;
diff --git a/src/map/script.c b/src/map/script.c
index 181ff350f..a5e45f503 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2699,13 +2699,13 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
#endif
#ifdef SCRIPT_DEBUG_DISASM
i = 0;
- while(i < script->pos) {
- int j = i;
- c_op op = script->get_com(script->buf,&i);
+ while (i < script->pos) {
+ c_op op = script->get_com(script->buf, &i);
+ int j = i; // Note: i is modified in the line above.
ShowMessage("%06x %s", i, script->op2name(op));
- j = i;
- switch(op) {
+
+ switch (op) {
case C_INT:
ShowMessage(" %d", script->get_num(script->buf,&i));
break;
@@ -3834,7 +3834,7 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
pcre *compiled_regex;
pcre_extra *extra_regex;
const char *pcre_error, *pcre_match;
- int pcre_erroroffset, offsetcount, i;
+ int pcre_erroroffset, offsetcount;
int offsets[256*3]; // (max_capturing_groups+1)*3
compiled_regex = libpcre->compile(s2, 0, &pcre_error, &pcre_erroroffset, NULL);
@@ -3875,8 +3875,9 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
return;
}
- if( op == C_RE_EQ ) {
- for( i = 0; i < offsetcount; i++ ) {
+ if (op == C_RE_EQ) {
+ int i;
+ for (i = 0; i < offsetcount; i++) {
libpcre->get_substring(s1, offsets, offsetcount, i, &pcre_match);
mapreg->setregstr(reference_uid(script->add_str("$@regexmatch$"), i), pcre_match);
libpcre->free_substring(pcre_match);
@@ -4920,7 +4921,7 @@ void script_load_translations(void) {
libconfig->destroy(&translations_conf);
if( total ) {
- struct DBIterator *main_iter, *sub_iter;
+ struct DBIterator *main_iter;
struct DBMap *string_db;
struct string_translation *st = NULL;
uint32 j = 0;
@@ -4929,9 +4930,9 @@ void script_load_translations(void) {
script->translation_buf_size = total;
main_iter = db_iterator(script->translation_db);
- for( string_db = dbi_first(main_iter); dbi_exists(main_iter); string_db = dbi_next(main_iter) ) {
- sub_iter = db_iterator(string_db);
- for( st = dbi_first(sub_iter); dbi_exists(sub_iter); st = dbi_next(sub_iter) ) {
+ for (string_db = dbi_first(main_iter); dbi_exists(main_iter); string_db = dbi_next(main_iter)) {
+ struct DBIterator *sub_iter = db_iterator(string_db);
+ for (st = dbi_first(sub_iter); dbi_exists(sub_iter); st = dbi_next(sub_iter)) {
script->translation_buf[j++] = st->buf;
}
dbi_destroy(sub_iter);
@@ -4956,8 +4957,8 @@ void script_load_translations(void) {
/**
*
**/
-const char * script_get_translation_file_name(const char *file) {
- static char file_name[200];
+const char *script_get_translation_file_name(const char *file)
+{
int i, len = (int)strlen(file), last_bar = -1, last_dot = -1;
for(i = 0; i < len; i++) {
@@ -4968,6 +4969,7 @@ const char * script_get_translation_file_name(const char *file) {
}
if( last_bar != -1 || last_dot != -1 ) {
+ static char file_name[200];
if( last_bar != -1 && last_dot < last_bar )
last_dot = -1;
safestrncpy(file_name, file+(last_bar >= 0 ? last_bar+1 : 0), ( last_dot >= 0 ? ( last_bar >= 0 ? last_dot - last_bar : last_dot ) : sizeof(file_name) ));
@@ -4999,7 +5001,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) {
atcommand->expand_message_table();
while(fgets(line, sizeof(line), fp)) {
- size_t len = strlen(line), cursor = 0;
+ size_t len = strlen(line);
if( len <= 1 )
continue;
@@ -5008,6 +5010,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) {
continue;
if( strncasecmp(line,"msgctxt \"", 9) == 0 ) {
+ int cursor = 0;
msgctxt[0] = '\0';
for(i = 9; i < len - 2; i++) {
if( line[i] == '\\' && line[i+1] == '"' ) {
@@ -5015,7 +5018,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) {
i++;
} else
msgctxt[cursor] = line[i];
- if( ++cursor >= sizeof(msgctxt) - 1 )
+ if (++cursor >= (int)sizeof(msgctxt) - 1)
break;
}
msgctxt[cursor] = '\0';
@@ -18643,22 +18646,11 @@ BUILDIN(getcharip) {
return false;
}
- /* check for IP */
- if (!sockt->session[sd->fd]->client_addr) {
+ if (sd->fd == 0 || sockt->session[sd->fd] == NULL || sockt->session[sd->fd]->client_addr == 0) {
script_pushconststr(st, "");
- return true;
- }
-
- /* return the client ip_addr converted for output */
- if (sd && sd->fd && sockt->session[sd->fd])
- {
- /* initiliaze */
- const char *ip_addr = NULL;
- uint32 ip;
-
- /* set ip, ip_addr and convert to ip and push str */
- ip = sockt->session[sd->fd]->client_addr;
- ip_addr = sockt->ip2str(ip, NULL);
+ } else {
+ uint32 ip = sockt->session[sd->fd]->client_addr;
+ const char *ip_addr = sockt->ip2str(ip, NULL);
script_pushstrcopy(st, ip_addr);
}
diff --git a/src/map/skill.c b/src/map/skill.c
index 3004bf0e9..51d0792e3 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -15995,14 +15995,14 @@ int skill_enchant_elemental_end (struct block_list *bl, int type) {
bool skill_check_cloaking(struct block_list *bl, struct status_change_entry *sce)
{
- static int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1};
- static int dy[] = {-1, 0, 1, 0, -1, -1, 1, 1};
bool wall = true;
if( (bl->type == BL_PC && battle_config.pc_cloak_check_type&1)
|| (bl->type != BL_PC && battle_config.monster_cloak_check_type&1)
) {
//Check for walls.
+ static int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1};
+ static int dy[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int i;
ARR_FIND( 0, 8, i, map->getcell(bl->m, bl, bl->x+dx[i], bl->y+dy[i], CELL_CHKNOPASS) != 0 );
if( i == 8 )
@@ -16060,11 +16060,11 @@ int skill_check_cloaking_end(struct block_list *bl, va_list ap)
bool skill_check_camouflage(struct block_list *bl, struct status_change_entry *sce)
{
- static int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1};
- static int dy[] = {-1, 0, 1, 0, -1, -1, 1, 1};
bool wall = true;
if( bl->type == BL_PC ) { //Check for walls.
+ static int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1};
+ static int dy[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int i;
ARR_FIND( 0, 8, i, map->getcell(bl->m, bl, bl->x+dx[i], bl->y+dy[i], CELL_CHKNOPASS) != 0 );
if( i == 8 )
diff --git a/src/map/status.c b/src/map/status.c
index 39bb25737..34bfd06b5 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -11613,7 +11613,7 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) {
if( --(sce->val4) > 0 ) {
struct block_list *src = map->id2bl(sce->val2);
int damage;
- if( !src || (src && (status->isdead(src) || src->m != bl->m || distance_bl(src, bl) >= 12)) )
+ if (src == NULL || (status->isdead(src) || src->m != bl->m || distance_bl(src, bl) >= 12))
break;
map->freeblock_lock();
damage = sce->val3;
@@ -12964,7 +12964,7 @@ int status_readdb_refine_libconfig(const char *filename) {
struct config_t refine_db_conf;
struct config_setting_t *r;
char filepath[256];
- int i = 0, count = 0,type = 0;
+ int i = 0, count = 0;
sprintf(filepath, "%s/%s", map->db_path, filename);
if (!libconfig->load_file(&refine_db_conf, filepath))
@@ -12974,10 +12974,13 @@ int status_readdb_refine_libconfig(const char *filename) {
while((r = libconfig->setting_get_elem(refine_db_conf.root,i++))) {
char *name = config_setting_name(r);
- if((type=status->readdb_refine_libconfig_sub(r, name, filename))) {
- if( duplicate[type-1] ) {
+ int type = status->readdb_refine_libconfig_sub(r, name, filename);
+ if (type != 0) {
+ if (duplicate[type-1]) {
ShowWarning("status_readdb_refine_libconfig: duplicate entry for %s in \"%s\", overwriting previous entry...\n", name, filename);
- } else duplicate[type-1] = true;
+ } else {
+ duplicate[type-1] = true;
+ }
count++;
}
}