summaryrefslogtreecommitdiff
path: root/src/map/mob.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-09-21 03:47:19 +0200
committerHaru <haru@dotalux.com>2013-09-21 03:50:26 +0200
commit51241f66ad6e78cf56b91c41e524c00a1d5abeb2 (patch)
tree0b03082e62425d126bbff387f09cad4ab0f2bd24 /src/map/mob.c
parent556834d0508101b70660c5904b24adacacced3e0 (diff)
downloadhercules-51241f66ad6e78cf56b91c41e524c00a1d5abeb2.tar.gz
hercules-51241f66ad6e78cf56b91c41e524c00a1d5abeb2.tar.bz2
hercules-51241f66ad6e78cf56b91c41e524c00a1d5abeb2.tar.xz
hercules-51241f66ad6e78cf56b91c41e524c00a1d5abeb2.zip
Fixed a potentially negative array subscript causing a mapserver crash
- Fixes bugreport:7717, special thanks to quesoph http://hercules.ws/board/tracker/issue-7717-map-crash-when-warping-on-a-floating-npc/ - Also changed various map[foo].index to the map_id2index(foo) macro. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/mob.c')
-rw-r--r--src/map/mob.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index 146f82239..0c1ad0d5d 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -457,8 +457,7 @@ struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int
/*==========================================
* Spawn a single mob on the specified coordinates.
*------------------------------------------*/
-int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const char* mobname, int class_, int amount, const char* event, unsigned int size, unsigned int ai)
-{
+int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const char* mobname, int class_, int amount, const char* event, unsigned int size, unsigned int ai) {
struct mob_data* md = NULL;
int count, lv;
@@ -467,26 +466,22 @@ int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const
lv = (sd) ? sd->status.base_level : 255;
- for (count = 0; count < amount; count++)
- {
+ for (count = 0; count < amount; count++) {
int c = (class_ >= 0) ? class_ : mob->get_random_id(-class_ - 1, (battle_config.random_monster_checklv) ? 3 : 1, lv);
md = mob->once_spawn_sub((sd) ? &sd->bl : NULL, m, x, y, mobname, c, event, size, ai);
if (!md)
continue;
- if (class_ == MOBID_EMPERIUM)
- {
- struct guild_castle* gc = guild->mapindex2gc(map[m].index);
+ if (class_ == MOBID_EMPERIUM) {
+ struct guild_castle* gc = guild->mapindex2gc(map_id2index(m));
struct guild* g = (gc) ? guild->search(gc->guild_id) : NULL;
- if (gc)
- {
+ if (gc) {
md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data));
md->guardian_data->castle = gc;
md->guardian_data->number = MAX_GUARDIANS;
md->guardian_data->guild_id = gc->guild_id;
- if (g)
- {
+ if (g) {
md->guardian_data->emblem_id = g->emblem_id;
memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH);
}
@@ -497,10 +492,11 @@ int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const
mob->spawn(md);
- if (class_ < 0 && battle_config.dead_branch_active)
+ if (class_ < 0 && battle_config.dead_branch_active) {
//Behold Aegis's masterful decisions yet again...
//"I understand the "Aggressive" part, but the "Can Move" and "Can Attack" is just stupid" - Poki#3
sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE|MD_CANATTACK|MD_CANMOVE|MD_ANGRY, 0, 60000);
+ }
}
return (md) ? md->bl.id : 0; // id of last spawned mob
@@ -1182,12 +1178,12 @@ int mob_warpchase_sub(struct block_list *bl,va_list ap) {
if(nd->subtype != WARP)
return 0; //Not a warp
- if(nd->u.warp.mapindex != map[target->m].index)
+ if(nd->u.warp.mapindex != map_id2index(target->m))
return 0; //Does not lead to the same map.
cur_distance = distance_blxy(target, nd->u.warp.x, nd->u.warp.y);
- if (cur_distance < *min_distance)
- { //Pick warp that leads closest to target.
+ if (cur_distance < *min_distance) {
+ //Pick warp that leads closest to target.
*target_nd = nd;
*min_distance = cur_distance;
return 1;