summaryrefslogtreecommitdiff
path: root/src/map/pc.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/pc.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/pc.c')
-rw-r--r--src/map/pc.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 995687170..4738d816a 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4825,7 +4825,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
}
if( i != sd->instances ) {
m = instances[sd->instance[i]].map[j];
- mapindex = map[m].index;
+ mapindex = map_id2index(m);
stop = true;
}
}
@@ -4839,7 +4839,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
}
if( i != p->instances ) {
m = instances[p->instance[i]].map[j];
- mapindex = map[m].index;
+ mapindex = map_id2index(m);
stop = true;
}
}
@@ -4853,7 +4853,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
}
if( i != sd->guild->instances ) {
m = instances[sd->guild->instance[i]].map[j];
- mapindex = map[m].index;
+ mapindex = map_id2index(m);
stop = true;
}
}
@@ -5009,8 +5009,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
* 0 = fail or FIXME success (from pc->setpos)
* x(1|2) = fail
*------------------------------------------*/
-int pc_randomwarp(struct map_session_data *sd, clr_type type)
-{
+int pc_randomwarp(struct map_session_data *sd, clr_type type) {
int x,y,i=0;
int16 m;
@@ -5021,13 +5020,13 @@ int pc_randomwarp(struct map_session_data *sd, clr_type type)
if (map[sd->bl.m].flag.noteleport) //Teleport forbidden
return 0;
- do{
+ do {
x=rnd()%(map[m].xs-2)+1;
y=rnd()%(map[m].ys-2)+1;
- }while(iMap->getcell(m,x,y,CELL_CHKNOPASS) && (i++)<1000 );
+ } while( iMap->getcell(m,x,y,CELL_CHKNOPASS) && (i++) < 1000 );
if (i < 1000)
- return pc->setpos(sd,map[sd->bl.m].index,x,y,type);
+ return pc->setpos(sd,map_id2index(sd->bl.m),x,y,type);
return 0;
}