瀏覽代碼

Added null pointer checks in map_delblock (#7930)

Atemo 1 年之前
父節點
當前提交
e965e2794b
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      src/map/map.cpp

+ 7 - 1
src/map/map.cpp

@@ -349,7 +349,7 @@ int map_addblock(struct block_list* bl)
 
 	struct map_data *mapdata = map_getmapdata(m);
 
-	if (mapdata->cell == nullptr) // Player warped to a freed map. Stop them!
+	if (mapdata == nullptr || mapdata->cell == nullptr) // Player warped to a freed map. Stop them!
 		return 1;
 
 	if( x < 0 || x >= mapdata->xs || y < 0 || y >= mapdata->ys )
@@ -402,6 +402,8 @@ int map_delblock(struct block_list* bl)
 
 	struct map_data *mapdata = map_getmapdata(bl->m);
 
+	nullpo_ret(mapdata);
+
 	pos = bl->x/BLOCK_SIZE+(bl->y/BLOCK_SIZE)*mapdata->bxs;
 
 	if (bl->next)
@@ -409,8 +411,10 @@ int map_delblock(struct block_list* bl)
 	if (bl->prev == &bl_head) {
 	//Since the head of the list, update the block_list map of []
 		if (bl->type == BL_MOB) {
+			nullpo_ret(mapdata->block_mob);
 			mapdata->block_mob[pos] = bl->next;
 		} else {
+			nullpo_ret(mapdata->block);
 			mapdata->block[pos] = bl->next;
 		}
 	} else {
@@ -434,6 +438,8 @@ int map_delblock(struct block_list* bl)
  */
 int map_moveblock(struct block_list *bl, int x1, int y1, t_tick tick)
 {
+	nullpo_ret(bl);
+
 	int x0 = bl->x, y0 = bl->y;
 	status_change *sc = NULL;
 	int moveblock = ( x0/BLOCK_SIZE != x1/BLOCK_SIZE || y0/BLOCK_SIZE != y1/BLOCK_SIZE);