Przeglądaj źródła

updates

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@799 54d463be-8e91-2dee-dedb-b68131a5f0ec
amber 20 lat temu
rodzic
commit
2c5b677475
3 zmienionych plików z 54 dodań i 3 usunięć
  1. 1 1
      Changelog.txt
  2. 3 1
      src/map/pc.c
  3. 50 1
      src/map/pet.c

+ 1 - 1
Changelog.txt

@@ -1,6 +1,6 @@
 Date	Added
 12/26
-	* Fixed some array bounds errors (SVN 798) [MouseJstr]
+	* Fixed some array bounds errors (SVN 799) [MouseJstr]
 	* @mapexit (and do_final) now persist all data to the
 	  char server before exiting to eliminate storage/inventory
 	  inconsistancies.. [MouseJstr]  (SVN 793)

+ 3 - 1
src/map/pc.c

@@ -3873,7 +3873,7 @@ int pc_setpos(struct map_session_data *sd,char *mapname_org,int x,int y,int clrt
 		sd->disguise=0;
 	}
 
-	memcpy(mapname,mapname_org,24);
+	strncpy(mapname,mapname_org,sizeof(mapname));
 	mapname[16]=0;
 	if(strstr(mapname,".gat")==NULL && strstr(mapname,".afm")==NULL && strlen(mapname)<16){
 		strcat(mapname,".gat");
@@ -7686,6 +7686,8 @@ static int pc_autosave_sub(struct map_session_data *sd,va_list ap)
 {
 	nullpo_retr(0, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(save_flag==0 && sd->fd>last_save_fd){
 		struct guild_castle *gc=NULL;
 		int i;

+ 50 - 1
src/map/pet.c

@@ -49,6 +49,8 @@ static int calc_next_walk_step(struct pet_data *pd)
 {
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if(pd->walkpath.path_pos>=pd->walkpath.path_len)
 		return -1;
 	if(pd->walkpath.path[pd->walkpath.path_pos]&1)
@@ -60,6 +62,8 @@ static int pet_performance_val(struct map_session_data *sd)
 {
 	nullpo_retr(0, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->pet.intimate > 900)
 		return (sd->petDB->s_perfor > 0)? 4:3;
 	else if(sd->pet.intimate > 750)
@@ -72,6 +76,8 @@ int pet_hungry_val(struct map_session_data *sd)
 {
 	nullpo_retr(0, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->pet.hungry > 90)
 		return 4;
 	else if(sd->pet.hungry > 75)
@@ -90,6 +96,8 @@ static int pet_can_reach(struct pet_data *pd,int x,int y)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if( pd->bl.x==x && pd->bl.y==y )	// 同じマス
 		return 1;
 
@@ -107,6 +115,8 @@ static int pet_calc_pos(struct pet_data *pd,int tx,int ty,int dir)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	pd->to_x = tx;
 	pd->to_y = ty;
 
@@ -162,6 +172,8 @@ static int pet_attack(struct pet_data *pd,unsigned int tick,int data)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	pd->state.state=MS_IDLE;
 
 	md=(struct mob_data *)map_id2bl(pd->target_id);
@@ -208,6 +220,8 @@ static int pet_walk(struct pet_data *pd,unsigned int tick,int data)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	pd->state.state=MS_IDLE;
 	if(pd->walkpath.path_pos >= pd->walkpath.path_len || pd->walkpath.path_pos != data)
 		return 0;
@@ -273,6 +287,8 @@ int pet_stopattack(struct pet_data *pd)
 {
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	pd->target_id=0;
 	if(pd->state.state == MS_ATTACK)
 		pet_changestate(pd,MS_IDLE,0);
@@ -290,6 +306,8 @@ int pet_target_check(struct map_session_data *sd,struct block_list *bl,int type)
 
 	pd = sd->pd;
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if(bl && pd && bl->type == BL_MOB && sd->pet.intimate > 900 && sd->pet.hungry > 0 && pd->class != battle_get_class(bl)
 		&& pd->state.state != MS_DELAY) {
 		mode=mob_db[pd->class].mode;
@@ -331,6 +349,8 @@ int pet_changestate(struct pet_data *pd,int state,int type)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if(pd->timer != -1)
 		delete_timer(pd->timer,pet_timer);
 	pd->timer=-1;
@@ -368,6 +388,8 @@ static int pet_timer(int tid,unsigned int tick,int id,int data)
 	if(pd == NULL || pd->bl.type != BL_PET)
 		return 1;
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if(pd->timer != tid){
 		if(battle_config.error_log)
 			printf("pet_timer %d != %d\n",pd->timer,tid);
@@ -403,6 +425,8 @@ static int pet_walktoxy_sub(struct pet_data *pd)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if(path_search(&wpd,pd->bl.m,pd->bl.x,pd->bl.y,pd->to_x,pd->to_y,0))
 		return 1;
 	memcpy(&pd->walkpath,&wpd,sizeof(wpd));
@@ -422,6 +446,8 @@ int pet_walktoxy(struct pet_data *pd,int x,int y)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if(pd->state.state == MS_WALK && path_search(&wpd,pd->bl.m,pd->bl.x,pd->bl.y,x,y,0))
 		return 1;
 
@@ -441,6 +467,8 @@ int pet_stop_walking(struct pet_data *pd,int type)
 {
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	if(pd->state.state == MS_WALK || pd->state.state == MS_IDLE) {
 		pd->walkpath.path_len=0;
 		pd->to_x=pd->bl.x;
@@ -461,10 +489,13 @@ static int pet_hungry(int tid,unsigned int tick,int id,int data)
 	struct map_session_data *sd;
 	int interval,t;
 
+
 	sd=map_id2sd(id);
 	if(sd==NULL)
 		return 1;
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->pet_hungry_timer != tid){
 		if(battle_config.error_log)
 			printf("pet_hungry_timer %d != %d\n",sd->pet_hungry_timer,tid);
@@ -556,6 +587,8 @@ int pet_remove_map(struct map_session_data *sd)
 {
 	nullpo_retr(0, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->status.pet_id && sd->pd) {
 
 		struct pet_data *pd=sd->pd; // [Valaris]
@@ -598,6 +631,8 @@ int pet_performance(struct map_session_data *sd)
 	nullpo_retr(0, sd);
 	nullpo_retr(0, pd=sd->pd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	pet_stop_walking(pd,2000<<8);
 	clif_pet_performance(&pd->bl,rand()%pet_performance_val(sd) + 1);
 	// ルートしたItemを落とさせる
@@ -613,6 +648,8 @@ int pet_return_egg(struct map_session_data *sd)
 
 	nullpo_retr(0, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->status.pet_id && sd->pd) {
 		struct pet_data *pd=sd->pd;
 		pet_remove_map(sd);
@@ -659,6 +696,8 @@ int pet_data_init(struct map_session_data *sd)
 
 	nullpo_retr(1, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->status.account_id != sd->pet.account_id || sd->status.char_id != sd->pet.char_id ||
 		sd->status.pet_id != sd->pet.pet_id) {
 		sd->status.pet_id = 0;
@@ -719,6 +758,8 @@ int pet_birth_process(struct map_session_data *sd)
 {
 	nullpo_retr(1, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->status.pet_id && sd->pet.incuvate == 1) {
 		sd->status.pet_id = 0;
 		return 1;
@@ -747,6 +788,8 @@ int pet_birth_process(struct map_session_data *sd)
 	clif_pet_equip(sd->pd,sd->pet.equip);
 	clif_send_petstatus(sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	return 0;
 }
 
@@ -869,7 +912,7 @@ int pet_get_egg(int account_id,int pet_id,int flag)
 			tmp_item.nameid = pet_db[i].EggID;
 			tmp_item.identify = 1;
 			tmp_item.card[0] = 0xff00;
-			*((long *)(&tmp_item.card[1])) = pet_id;
+			tmp_item.card[1] = pet_id;
 			tmp_item.card[3] = sd->pet.rename_flag;
 			if((ret = pc_additem(sd,&tmp_item,1))) {
 				clif_additem(sd,0,0,ret);
@@ -991,6 +1034,8 @@ int pet_food(struct map_session_data *sd)
 
 	nullpo_retr(1, sd);
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(sd->petDB == NULL)
 		return 1;
 	i=pc_search_inventory(sd,sd->petDB->FoodID);
@@ -1048,6 +1093,8 @@ static int pet_randomwalk(struct pet_data *pd,int tick)
 
 	nullpo_retr(0, pd);
 
+	Assert((pd->msd == 0) || (pd->msd->pd == pd));
+
 	speed = battle_get_speed(&pd->bl);
 
 	if(DIFF_TICK(pd->next_walktime,tick) < 0){
@@ -1105,6 +1152,8 @@ static int pet_ai_sub_hard(struct pet_data *pd,unsigned int tick)
 
 	sd = pd->msd;
 
+	Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); 
+
 	if(pd->bl.prev == NULL || sd == NULL || sd->bl.prev == NULL)
 		return 0;