summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-05-19 02:33:27 +0200
committerHaru <haru@dotalux.com>2015-05-19 03:07:38 +0200
commit0c1ce8e1c427d665c207512a0e858872ef80672d (patch)
tree9e5a29d39875fe0cf74d93400b2a815fa92c3733
parent46c6e66222cc3aaf1b1ea08794a6b818d7065b67 (diff)
downloadhercules-0c1ce8e1c427d665c207512a0e858872ef80672d.tar.gz
hercules-0c1ce8e1c427d665c207512a0e858872ef80672d.tar.bz2
hercules-0c1ce8e1c427d665c207512a0e858872ef80672d.tar.xz
hercules-0c1ce8e1c427d665c207512a0e858872ef80672d.zip
Fixed some issues reported by coverity scan [1/3]
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--src/map/npc.c7
-rw-r--r--src/map/script.c2
-rw-r--r--src/map/skill.c5
-rw-r--r--src/tool/mapcache.c63
4 files changed, 49 insertions, 28 deletions
diff --git a/src/map/npc.c b/src/map/npc.c
index 1721e3db3..c66f6533b 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -3815,13 +3815,14 @@ const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char
}
else if (!strcmpi(w3,"battleground")) {
struct map_zone_data *zone;
- if( state ) {
- if( sscanf(w4, "%d", &state) == 1 )
+ if (state) {
+ if (w4 && sscanf(w4, "%d", &state) == 1)
map->list[m].flag.battleground = state;
else
map->list[m].flag.battleground = 1; // Default value
- } else
+ } else {
map->list[m].flag.battleground = 0;
+ }
if( map->list[m].flag.battleground && map->list[m].flag.pvp ) {
map->list[m].flag.pvp = 0;
diff --git a/src/map/script.c b/src/map/script.c
index a86ccfdc9..1559a2cfa 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -17288,7 +17288,9 @@ BUILDIN(waitingroom2bg) {
return true;
}
+ Assert_retr(false, cd->users < MAX_CHAT_USERS);
n = cd->users; // This is always < MAX_CHAT_USERS
+
for (i = 0; i < n && i < MAX_BG_MEMBERS; i++) {
struct map_session_data *sd = cd->usersd[i];
if (sd != NULL && bg->team_join(bg_id, sd))
diff --git a/src/map/skill.c b/src/map/skill.c
index 41d872b77..77e9f24aa 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -2320,9 +2320,8 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr
if( damage && sc && sc->data[SC_GENSOU] && dmg.flag&BF_MAGIC ){
struct block_list *nbl;
nbl = battle->get_enemy_area(bl,bl->x,bl->y,2,BL_CHAR,bl->id);
- if( nbl ){ // Only one target is chosen.
- int temp = (int)(damage / (float)(10 / skill_lv));
- clif->skill_damage(bl, nbl, tick, status_get_amotion(src), 0, status_fix_damage(bl,nbl,temp,0), 1, OB_OBOROGENSOU_TRANSITION_ATK, -1, 6);
+ if (nbl) { // Only one target is chosen.
+ clif->skill_damage(bl, nbl, tick, status_get_amotion(src), 0, status_fix_damage(bl,nbl,damage * skill_lv / 10,0), 1, OB_OBOROGENSOU_TRANSITION_ATK, -1, 6);
}
}
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c
index 4b2b4bd49..5cdaf6c94 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -114,8 +114,14 @@ int read_map(char *name, struct map_data *m)
return 1;
}
-// Adds a map to the cache
-void cache_map(char *name, struct map_data *m)
+/**
+ * Adds a map to the cache.
+ *
+ * @param name The map name.
+ * @param m Map data to cache.
+ * @retval true if the map was successfully added to the cache.
+ */
+bool cache_map(char *name, struct map_data *m)
{
struct map_info info;
unsigned long len;
@@ -130,14 +136,18 @@ void cache_map(char *name, struct map_data *m)
// Fill the map header
safestrncpy(info.name, name, MAP_NAME_LENGTH);
if (strlen(name) > MAP_NAME_LENGTH) // It does not hurt to warn that there are maps with name longer than allowed.
- ShowWarning("Map name '%s' (length %"PRIuS") is too long. Truncating to '%s' (lentgh %d).\n",
+ ShowWarning("Map name '%s' (length %"PRIuS") is too long. Truncating to '%s' (length %d).\n",
name, strlen(name), info.name, MAP_NAME_LENGTH);
info.xs = MakeShortLE(m->xs);
info.ys = MakeShortLE(m->ys);
info.len = MakeLongLE((uint32)len);
// Append map header then compressed cells at the end of the file
- fseek(map_cache_fp, header.file_size, SEEK_SET);
+ if (fseek(map_cache_fp, header.file_size, SEEK_SET) != 0) {
+ aFree(write_buf);
+ aFree(m->cells);
+ return false;
+ }
fwrite(&info, sizeof(struct map_info), 1, map_cache_fp);
fwrite(write_buf, 1, len, map_cache_fp);
header.file_size += sizeof(struct map_info) + len;
@@ -146,26 +156,34 @@ void cache_map(char *name, struct map_data *m)
aFree(write_buf);
aFree(m->cells);
- return;
+ return true;
}
-// Checks whether a map is already is the cache
-int find_map(char *name)
+/**
+ * Checks whether a map is already is the cache.
+ *
+ * @param name The map name.
+ * @retval true if the map is already cached.
+ */
+bool find_map(char *name)
{
int i;
struct map_info info;
- fseek(map_cache_fp, sizeof(struct main_header), SEEK_SET);
-
- for(i = 0; i < header.map_count; i++) {
- if(fread(&info, sizeof(info), 1, map_cache_fp) != 1) printf("An error as occured in fread while reading map_cache\n");
- if(strcmp(name, info.name) == 0) // Map found
- return 1;
- else // Map not found, jump to the beginning of the next map info header
- fseek(map_cache_fp, GetLong((unsigned char *)&(info.len)), SEEK_CUR);
+ if (fseek(map_cache_fp, sizeof(struct main_header), SEEK_SET) != 0)
+ return false;
+
+ for (i = 0; i < header.map_count; i++) {
+ if (fread(&info, sizeof(info), 1, map_cache_fp) != 1)
+ printf("An error as occured in fread while reading map_cache\n");
+ if (strcmp(name, info.name) == 0) // Map found
+ return true;
+ // Map not found, jump to the beginning of the next map info header
+ if (fseek(map_cache_fp, GetLong((unsigned char *)&(info.len)), SEEK_CUR) != 0)
+ return false;
}
- return 0;
+ return false;
}
// Cuts the extension from a map name
@@ -314,14 +332,15 @@ int do_init(int argc, char** argv)
name[MAP_NAME_LENGTH_EXT-1] = '\0';
remove_extension(name);
- if(find_map(name))
+ if (find_map(name)) {
ShowInfo("Map '"CL_WHITE"%s"CL_RESET"' already in cache.\n", name);
- else if(read_map(name, &map)) {
- cache_map(name, &map);
- ShowInfo("Map '"CL_WHITE"%s"CL_RESET"' successfully cached.\n", name);
- } else
+ } else if(!read_map(name, &map)) {
ShowError("Map '"CL_WHITE"%s"CL_RESET"' not found!\n", name);
-
+ } else if (!cache_map(name, &map)) {
+ ShowError("Map '"CL_WHITE"%s"CL_RESET"' failed to cache (write error).\n", name);
+ } else {
+ ShowInfo("Map '"CL_WHITE"%s"CL_RESET"' successfully cached.\n", name);
+ }
}
ShowStatus("Closing map list: %s\n", map_list_file);