From 51241f66ad6e78cf56b91c41e524c00a1d5abeb2 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 21 Sep 2013 03:47:19 +0200 Subject: 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 --- src/map/pc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/map/pc.c') 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; } -- cgit v1.2.3-60-g2f50