浏览代码

* Using malloc for memory allocations that doesn't need to be pre-initialized.
* Eliminated initializations for pointers returned by calloc.
* Moved grfio_final to do_init since it's not used after server boot.
* Optimized scripts to return CONSTSTR instead of allocating memory just to return a constant string. Some buildin functions still need work.
* Disabled graph since it doesn't work yet.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@6355 54d463be-8e91-2dee-dedb-b68131a5f0ec

Lance 19 年之前
父节点
当前提交
020b35d68a
共有 15 个文件被更改,包括 119 次插入134 次删除
  1. 9 0
      Changelog-Trunk.txt
  2. 1 1
      src/common/graph.c
  3. 7 7
      src/common/grfio.c
  4. 3 3
      src/map/atcommand.c
  5. 1 1
      src/map/charsave.c
  6. 2 2
      src/map/chat.c
  7. 3 3
      src/map/chrif.c
  8. 10 13
      src/map/clif.c
  9. 3 3
      src/map/guild.c
  10. 2 2
      src/map/irc.c
  11. 18 24
      src/map/map.c
  12. 17 18
      src/map/npc.c
  13. 2 2
      src/map/pc.c
  14. 37 52
      src/map/script.c
  15. 4 3
      src/map/skill.c

+ 9 - 0
Changelog-Trunk.txt

@@ -2,6 +2,15 @@ Date	Added
 
 
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
+
+2006/04/29
+	* Using malloc for memory allocations that doesn't need to be pre-initialized.
+	* Eliminated initializations for pointers returned by calloc.
+	* Moved grfio_final to do_init since it's not used after server boot.
+	* Optimized scripts to return CONSTSTR instead of allocating memory just to return
+	  a constant string. Some buildin functions still need work. 
+	* Disabled graph since it doesn't work yet. [Lance]
+
 2006/04/28
 2006/04/28
 	* Modified the mob_db structure. The mvp related columns were moved to
 	* Modified the mob_db structure. The mvp related columns were moved to
 	  before the drops, amount of drops increased from 10 to 15. [Skotlex]
 	  before the drops, amount of drops increased from 10 to 15. [Skotlex]

+ 1 - 1
src/common/graph.c

@@ -2,7 +2,7 @@
 // For more information, see LICENCE in the main folder
 // For more information, see LICENCE in the main folder
 
 
 // graph creation is enabled
 // graph creation is enabled
-#define ENABLE_GRAPH
+// #define ENABLE_GRAPH
 
 
 #ifdef ENABLE_GRAPH
 #ifdef ENABLE_GRAPH
 
 

+ 7 - 7
src/common/grfio.c

@@ -591,7 +591,7 @@ void* grfio_reads(char *fname, int *size)
 				lentry.declen = ftell(in);
 				lentry.declen = ftell(in);
 			}
 			}
 			fseek(in,0,0);	// SEEK_SET
 			fseek(in,0,0);	// SEEK_SET
-			buf2 = (unsigned char *)aCallocA(lentry.declen + 1024, 1);
+			buf2 = (unsigned char *)aMallocA(lentry.declen + 1024);
 			fread(buf2, 1, lentry.declen, in);
 			fread(buf2, 1, lentry.declen, in);
 			fclose(in);
 			fclose(in);
 			strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
 			strncpy(lentry.fn, fname, sizeof(lentry.fn) - 1);
@@ -611,11 +611,11 @@ void* grfio_reads(char *fname, int *size)
 		char *gfname = gentry_table[entry->gentry - 1];
 		char *gfname = gentry_table[entry->gentry - 1];
 		in = fopen(gfname, "rb");
 		in = fopen(gfname, "rb");
 		if(in != NULL) {
 		if(in != NULL) {
-			unsigned char *buf = (unsigned char *)aCallocA(entry->srclen_aligned + 1024, 1);
+			unsigned char *buf = (unsigned char *)aMallocA(entry->srclen_aligned + 1024);
 			fseek(in, entry->srcpos, 0);
 			fseek(in, entry->srcpos, 0);
 			fread(buf, 1, entry->srclen_aligned, in);
 			fread(buf, 1, entry->srclen_aligned, in);
 			fclose(in);
 			fclose(in);
-			buf2 = (unsigned char *)aCallocA(entry->declen + 1024, 1);
+			buf2 = (unsigned char *)aMallocA(entry->declen + 1024);
 			if (entry->type == 1 || entry->type == 3 || entry->type == 5) {
 			if (entry->type == 1 || entry->type == 3 || entry->type == 5) {
 				uLongf len;
 				uLongf len;
 				if (entry->cycle >= 0)
 				if (entry->cycle >= 0)
@@ -694,7 +694,7 @@ static int grfio_entryread(char *gfname,int gentry)
 
 
 	if (grf_version == 0x01) {	//****** Grf version 01xx ******
 	if (grf_version == 0x01) {	//****** Grf version 01xx ******
 		list_size = grf_size - ftell(fp);
 		list_size = grf_size - ftell(fp);
-		grf_filelist = (unsigned char *) aCallocA(list_size, 1);
+		grf_filelist = (unsigned char *) aMallocA(list_size);
 		/*if (grf_filelist == NULL){
 		/*if (grf_filelist == NULL){
 			fclose(fp);
 			fclose(fp);
 			ShowError("out of memory : grf_filelist\n");
 			ShowError("out of memory : grf_filelist\n");
@@ -770,13 +770,13 @@ static int grfio_entryread(char *gfname,int gentry)
 			return 4;
 			return 4;
 		}
 		}
 
 
-		rBuf = (unsigned char *)aCallocA(rSize , 1);	// Get a Read Size
+		rBuf = (unsigned char *)aMallocA(rSize);	// Get a Read Size
 		/*if (rBuf==NULL) {
 		/*if (rBuf==NULL) {
 			fclose(fp);
 			fclose(fp);
 			ShowError("out of memory : grf compress entry table buffer\n");
 			ShowError("out of memory : grf compress entry table buffer\n");
 			return 3;
 			return 3;
 		}*/
 		}*/
-		grf_filelist = (unsigned char *)aCallocA(eSize , 1);	// Get a Extend Size
+		grf_filelist = (unsigned char *)aMallocA(eSize);	// Get a Extend Size
 		/*if (grf_filelist==NULL) {
 		/*if (grf_filelist==NULL) {
 			aFree(rBuf);
 			aFree(rBuf);
 			fclose(fp);
 			fclose(fp);
@@ -952,7 +952,7 @@ char *grfio_alloc_ptr(char *fname)
 		memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS);
 		memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS);
 	}
 	}
 	len = strlen( fname );
 	len = strlen( fname );
-	buf = (char*)aCallocA(len + 1, 1);
+	buf = (char*)aMallocA(len + 1);
 	strcpy(buf, fname);
 	strcpy(buf, fname);
 	gentry_table[gentry_entrys++] = buf;
 	gentry_table[gentry_entrys++] = buf;
 
 

+ 3 - 3
src/map/atcommand.c

@@ -889,7 +889,7 @@ int msg_config_read(const char *cfgName) {
 				if (msg_number >= 0 && msg_number < MAX_MSG) {
 				if (msg_number >= 0 && msg_number < MAX_MSG) {
 					if (msg_table[msg_number] != NULL)
 					if (msg_table[msg_number] != NULL)
 						aFree(msg_table[msg_number]);
 						aFree(msg_table[msg_number]);
-					msg_table[msg_number] = (char *)aCalloc(strlen(w2) + 1, sizeof (char));
+					msg_table[msg_number] = (char *)aMalloc((strlen(w2) + 1)*sizeof (char));
 					strcpy(msg_table[msg_number],w2);
 					strcpy(msg_table[msg_number],w2);
 				//	printf("message #%d: '%s'.\n", msg_number, msg_table[msg_number]);
 				//	printf("message #%d: '%s'.\n", msg_number, msg_table[msg_number]);
 				}
 				}
@@ -1951,8 +1951,8 @@ int atcommand_whozeny(
 		clif_displaymessage(fd, msg_table[28]); // No player found.
 		clif_displaymessage(fd, msg_table[28]); // No player found.
 		return 0;
 		return 0;
 	}	
 	}	
-	zeny = (int *)aCallocA(users, sizeof(int));
-	counted = (int *)aCallocA(users, sizeof(int));
+	zeny = (int *)aMallocA(users*sizeof(int));
+	counted = (int *)aMallocA(users*sizeof(int));
 	for (i = 0; i < users; i++) {
 	for (i = 0; i < users; i++) {
 		if ((pl_sd = pl_allsd[i])) {
 		if ((pl_sd = pl_allsd[i])) {
 				memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
 				memcpy(player_name, pl_sd->status.name, NAME_LENGTH);

+ 1 - 1
src/map/charsave.c

@@ -26,7 +26,7 @@ struct mmo_charstatus *charsave_loadchar(int charid){
 	char *str_p;
 	char *str_p;
 	friends = 0;
 	friends = 0;
 
 
-         c = (struct mmo_charstatus *)aMalloc(sizeof(struct mmo_charstatus));
+         c = (struct mmo_charstatus *)aCalloc(1,sizeof(struct mmo_charstatus));
 
 
          if(charid <= 0){
          if(charid <= 0){
          	ShowError("charsave_loadchar() charid <= 0! (%d)", charid);
          	ShowError("charsave_loadchar() charid <= 0! (%d)", charid);

+ 2 - 2
src/map/chat.c

@@ -28,7 +28,7 @@ int chat_createchat(struct map_session_data *sd,int limit,int pub,char* pass,cha
 	if (sd->chatID)
 	if (sd->chatID)
 		return 0;	//Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
 		return 0;	//Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
 	pc_stop_walking(sd,1);
 	pc_stop_walking(sd,1);
-	cd = (struct chat_data *) aCalloc(1,sizeof(struct chat_data));
+	cd = (struct chat_data *) aMalloc(sizeof(struct chat_data));
 
 
 	cd->limit = limit;
 	cd->limit = limit;
 	cd->pub = pub;
 	cd->pub = pub;
@@ -266,7 +266,7 @@ int chat_createnpcchat(struct npc_data *nd,int limit,int pub,int trigger,char* t
 
 
 	nullpo_retr(1, nd);
 	nullpo_retr(1, nd);
 
 
-	cd = (struct chat_data *) aCalloc(1,sizeof(struct chat_data));
+	cd = (struct chat_data *) aMalloc(sizeof(struct chat_data));
 
 
 	cd->limit = cd->trigger = limit;
 	cd->limit = cd->trigger = limit;
 	if(trigger>0)
 	if(trigger>0)

+ 3 - 3
src/map/chrif.c

@@ -465,7 +465,7 @@ void chrif_authreq(struct map_session_data *sd)
 			aFree(auth_data->char_dat);
 			aFree(auth_data->char_dat);
 		idb_remove(auth_db, sd->bl.id);
 		idb_remove(auth_db, sd->bl.id);
 	} else { //data from char server has not arrived yet.
 	} else { //data from char server has not arrived yet.
-		auth_data = aCalloc(1, sizeof(struct auth_node));
+		auth_data = aMalloc(sizeof(struct auth_node));
 		auth_data->sd = sd;
 		auth_data->sd = sd;
 		auth_data->fd = sd->fd;
 		auth_data->fd = sd->fd;
 		auth_data->account_id = sd->bl.id;
 		auth_data->account_id = sd->bl.id;
@@ -511,8 +511,8 @@ void chrif_authok(int fd) {
 		return;
 		return;
 	}
 	}
 	// Awaiting for client to connect.
 	// Awaiting for client to connect.
-	auth_data = (struct auth_node *)aCalloc(1, sizeof(struct auth_node));
-	auth_data->char_dat = (struct mmo_charstatus *) aCalloc(1, sizeof(struct mmo_charstatus));
+	auth_data = (struct auth_node *)aMalloc(sizeof(struct auth_node));
+	auth_data->char_dat = (struct mmo_charstatus *) aCalloc(1,sizeof(struct mmo_charstatus));
 
 
 	auth_data->account_id=RFIFOL(fd, 4);
 	auth_data->account_id=RFIFOL(fd, 4);
 	auth_data->login_id1=RFIFOL(fd, 8);
 	auth_data->login_id1=RFIFOL(fd, 8);

+ 10 - 13
src/map/clif.c

@@ -751,7 +751,7 @@ static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data
 
 
 int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
 int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
 	struct block_list *tbl;
 	struct block_list *tbl;
-	tbl = aCalloc(1, sizeof (struct block_list));
+	tbl = aMalloc(sizeof (struct block_list));
 	memcpy (tbl, bl, sizeof (struct block_list));
 	memcpy (tbl, bl, sizeof (struct block_list));
 	add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
 	add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
 
 
@@ -4811,7 +4811,7 @@ int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
 	int lp;
 	int lp;
 
 
 	lp = (flag & 0x10) ? 8 : 4;
 	lp = (flag & 0x10) ? 8 : 4;
-	buf = (unsigned char*)aCallocA(len + lp + 8, sizeof(unsigned char));
+	buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
 
 
 	WBUFW(buf,0) = 0x9a;
 	WBUFW(buf,0) = 0x9a;
 	WBUFW(buf,2) = len + lp;
 	WBUFW(buf,2) = len + lp;
@@ -4885,7 +4885,7 @@ void clif_MainChatMessage(char* message) {
 int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
 int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
 {
 {
 	unsigned char *buf;
 	unsigned char *buf;
-	buf = (unsigned char*)aCallocA(len + 16, sizeof(unsigned char));
+	buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
 	WBUFW(buf,0) = 0x1c3;
 	WBUFW(buf,0) = 0x1c3;
 	WBUFW(buf,2) = len + 16;
 	WBUFW(buf,2) = len + 16;
 	WBUFL(buf,4) = color;
 	WBUFL(buf,4) = color;
@@ -7062,7 +7062,7 @@ int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
 	struct map_session_data *sd;
 	struct map_session_data *sd;
 	unsigned char *buf;
 	unsigned char *buf;
 
 
-	buf = (unsigned char*)aCallocA(len + 4, sizeof(unsigned char));
+	buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
 
 
 	WBUFW(buf, 0) = 0x17f;
 	WBUFW(buf, 0) = 0x17f;
 	WBUFW(buf, 2) = len + 4;
 	WBUFW(buf, 2) = len + 4;
@@ -7368,7 +7368,7 @@ int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
 
 
 	nullpo_retr(0, sd);
 	nullpo_retr(0, sd);
 
 
-	buf = (unsigned char*)aCallocA(len + 5, sizeof(unsigned char));
+	buf = (unsigned char*)aMallocA((len + 5)*sizeof(unsigned char));
 
 
 	WBUFW(buf, 0) = 0x17f;
 	WBUFW(buf, 0) = 0x17f;
 	WBUFW(buf, 2) = len + 5;
 	WBUFW(buf, 2) = len + 5;
@@ -8458,7 +8458,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <
 	if (RFIFOW(fd,2)+4 < 128)
 	if (RFIFOW(fd,2)+4 < 128)
 		buf = buf2; //Use a static buffer.
 		buf = buf2; //Use a static buffer.
 	else
 	else
-		buf = (unsigned char*)aCallocA(RFIFOW(fd,2) + 4, sizeof(char));
+		buf = (unsigned char*)aMallocA((RFIFOW(fd,2) + 4)*sizeof(char));
 
 
 	// send message to others
 	// send message to others
 	WBUFW(buf,0) = 0x8d;
 	WBUFW(buf,0) = 0x8d;
@@ -8759,7 +8759,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <ni
 
 
 	//printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
 	//printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
 
 
-	gm_command = (char*)aCallocA(strlen((const char*)RFIFOP(fd,28)) + 28, sizeof(char)); // 24+3+(RFIFOW(fd,2)-28)+1 or 24+3+(strlen(RFIFOP(fd,28))+1 (size can be wrong with hacker)
+	gm_command = (char*)aMallocA((strlen((const char*)RFIFOP(fd,28)) + 28)*sizeof(char)); // 24+3+(RFIFOW(fd,2)-28)+1 or 24+3+(strlen(RFIFOP(fd,28))+1 (size can be wrong with hacker)
 
 
 	sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
 	sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
 	if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
 	if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
@@ -8787,8 +8787,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <ni
 		whisper_tmp += 4; //Skip the NPC: string part.
 		whisper_tmp += 4; //Skip the NPC: string part.
 		if ((npc = npc_name2id(whisper_tmp)))	
 		if ((npc = npc_name2id(whisper_tmp)))	
 		{
 		{
-			whisper_tmp=(char *)aCallocA(strlen((char *)(RFIFOP(fd,28)))+1,sizeof(char));
-			whisper_tmp[0]=0;
+			whisper_tmp=(char *)aMallocA((strlen((char *)(RFIFOP(fd,28)))+1)*sizeof(char));
 		   
 		   
 			sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));  
 			sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));  
 			for( j=0;whisper_tmp[j]!='\0';j++)
 			for( j=0;whisper_tmp[j]!='\0';j++)
@@ -8807,8 +8806,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <ni
 			split_data[i][j-k]='\0';
 			split_data[i][j-k]='\0';
 			
 			
 			aFree(whisper_tmp);
 			aFree(whisper_tmp);
-			whisper_tmp=(char *)aCallocA(15,sizeof(char));
-			whisper_tmp[0]=0;
+			whisper_tmp=(char *)aMallocA(15*sizeof(char));
 			
 			
 			for (j=0;j<=10;j++)
 			for (j=0;j<=10;j++)
 			{
 			{
@@ -8817,8 +8815,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <ni
 			}//You don't need to zero them, just reset them [Kevin]
 			}//You don't need to zero them, just reset them [Kevin]
 			
 			
 			aFree(whisper_tmp);
 			aFree(whisper_tmp);
-			whisper_tmp=(char *)aCallocA(strlen(npc->name)+18,sizeof(char));
-			whisper_tmp[0]=0;
+			whisper_tmp=(char *)aMallocA((strlen(npc->name)+18)*sizeof(char));
 			
 			
 			sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
 			sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
 			npc_event(sd,whisper_tmp,0); // Calls the NPC label 
 			npc_event(sd,whisper_tmp,0); // Calls the NPC label 

+ 3 - 3
src/map/guild.c

@@ -482,7 +482,7 @@ int guild_npc_request_info(int guild_id,const char *event)
 	if(event==NULL || *event==0)
 	if(event==NULL || *event==0)
 		return guild_request_info(guild_id);
 		return guild_request_info(guild_id);
 
 
-	ev=(struct eventlist *)aCalloc(1,sizeof(struct eventlist));
+	ev=(struct eventlist *)aMalloc(sizeof(struct eventlist));
 	memcpy(ev->name,event,strlen(event));
 	memcpy(ev->name,event,strlen(event));
 	//The one in the db becomes the next event from this.
 	//The one in the db becomes the next event from this.
 	ev->next=idb_put(guild_infoevent_db,guild_id,ev);
 	ev->next=idb_put(guild_infoevent_db,guild_id,ev);
@@ -1680,7 +1680,7 @@ int guild_addcastleinfoevent(int castle_id,int index,const char *name)
 	if( name==NULL || *name==0 )
 	if( name==NULL || *name==0 )
 		return 0;
 		return 0;
 
 
-	ev=(struct eventlist *)aCalloc(1,sizeof(struct eventlist));
+	ev=(struct eventlist *)aMalloc(sizeof(struct eventlist));
 	memcpy(ev->name,name,sizeof(ev->name));
 	memcpy(ev->name,name,sizeof(ev->name));
 	//The next event becomes whatever was currently stored.
 	//The next event becomes whatever was currently stored.
 	ev->next= idb_put(guild_castleinfoevent_db,code,ev);
 	ev->next= idb_put(guild_castleinfoevent_db,code,ev);
@@ -1904,7 +1904,7 @@ int guild_agit_break(struct mob_data *md)
 
 
 	nullpo_retr(0, md);
 	nullpo_retr(0, md);
 
 
-	evname=(char *)aCallocA(strlen(md->npc_event) + 1, sizeof(char));
+	evname=(char *)aMallocA((strlen(md->npc_event) + 1)*sizeof(char));
 
 
 	strcpy(evname,md->npc_event);
 	strcpy(evname,md->npc_event);
 // Now By User to Run [OnAgitBreak] NPC Event...
 // Now By User to Run [OnAgitBreak] NPC Event...

+ 2 - 2
src/map/irc.c

@@ -148,7 +148,7 @@ int irc_parse(int fd)
       	return 0;
       	return 0;
 	}
 	}
 	if (session[fd]->session_data == NULL){
 	if (session[fd]->session_data == NULL){
-		irc_si = (struct IRC_Session_Info*)aCalloc(1, sizeof(struct IRC_Session_Info));
+		irc_si = (struct IRC_Session_Info*)aMalloc(sizeof(struct IRC_Session_Info));
 		irc_si->fd = fd;
 		irc_si->fd = fd;
 		irc_si->state = 0;
 		irc_si->state = 0;
 		session[fd]->session_data = irc_si;
 		session[fd]->session_data = irc_si;
@@ -157,7 +157,7 @@ int irc_parse(int fd)
 		irc_si->fd = fd;
 		irc_si->fd = fd;
 	}
 	}
 	if(RFIFOREST(fd) > 0){
 	if(RFIFOREST(fd) > 0){
-		char *incoming_string=aCalloc(RFIFOREST(fd),sizeof(char));
+		char *incoming_string=aMalloc(RFIFOREST(fd)*sizeof(char));
 		memcpy(incoming_string,RFIFOP(fd,0),RFIFOREST(fd));
 		memcpy(incoming_string,RFIFOP(fd,0),RFIFOREST(fd));
 		send_to_parser(fd,incoming_string,"\n");
 		send_to_parser(fd,incoming_string,"\n");
 		RFIFOSKIP(fd,RFIFOREST(fd));
 		RFIFOSKIP(fd,RFIFOREST(fd));

+ 18 - 24
src/map/map.c

@@ -2738,7 +2738,7 @@ static int map_loadafm (struct map_data *m, char *fn)
 		ys = m->ys = afm_size[1];
 		ys = m->ys = afm_size[1];
 		m->water_height = map_waterheight(m->name);
 		m->water_height = map_waterheight(m->name);
 		// check this, unsigned where it might not need to be
 		// check this, unsigned where it might not need to be
-		m->gat = (unsigned char*)aCallocA(xs * ys, 1);
+		m->gat = (unsigned char*)aMallocA(xs * ys);
 
 
 		for (y = 0; y < ys; y++) {
 		for (y = 0; y < ys; y++) {
 			str = fgets(afm_line, sizeof(afm_line)-1, afm_file);
 			str = fgets(afm_line, sizeof(afm_line)-1, afm_file);
@@ -2834,7 +2834,7 @@ int map_readaf2 (struct map_data *m)
  */
  */
 int map_readgat (struct map_data *m)
 int map_readgat (struct map_data *m)
 {
 {
-	char fn[256], *pt;
+	char fn[256];
 	char *gat;
 	char *gat;
 	int wh,x,y,xs,ys;
 	int wh,x,y,xs,ys;
 	struct gat_1cell {float high[4]; int type;} *p = NULL;
 	struct gat_1cell {float high[4]; int type;} *p = NULL;
@@ -2842,13 +2842,6 @@ int map_readgat (struct map_data *m)
 	if (strstr(m->name,".gat") == NULL)
 	if (strstr(m->name,".gat") == NULL)
 		return 0;
 		return 0;
 
 
-	if ((pt = strstr(m->name,"<")) != NULL) { // [MouseJstr]
-		char buf[64];
-		*pt++ = '\0';
-		sprintf(buf,"data\\%s", pt);
-		m->alias = aStrdup(buf);
-	}
-
 	sprintf(fn,"data\\%s",m->name);
 	sprintf(fn,"data\\%s",m->name);
 
 
 	// read & convert fn
 	// read & convert fn
@@ -2859,7 +2852,7 @@ int map_readgat (struct map_data *m)
 
 
 	xs = m->xs = *(int*)(gat+6);
 	xs = m->xs = *(int*)(gat+6);
 	ys = m->ys = *(int*)(gat+10);
 	ys = m->ys = *(int*)(gat+10);
-	m->gat = (unsigned char *)aCallocA(m->xs * m->ys, sizeof(unsigned char));
+	m->gat = (unsigned char *)aMallocA((m->xs * m->ys)*sizeof(unsigned char));
 
 
 	m->water_height = wh = map_waterheight(m->name);
 	m->water_height = wh = map_waterheight(m->name);
 	for (y = 0; y < ys; y++) {
 	for (y = 0; y < ys; y++) {
@@ -3068,10 +3061,12 @@ int map_readallmaps (void)
 
 
 				size = map[i].bxs * map[i].bys * sizeof(int);
 				size = map[i].bxs * map[i].bys * sizeof(int);
 				map[i].block_count = (int*)aCallocA(size, 1);
 				map[i].block_count = (int*)aCallocA(size, 1);
-				memset(map[i].block_count, 0, size);
+				// Already initialized in aCallocA
+				//memset(map[i].block_count, 0, size);
 
 
 				map[i].block_mob_count = (int*)aCallocA(size, 1);
 				map[i].block_mob_count = (int*)aCallocA(size, 1);
-				memset(map[i].block_mob_count, 0, size);
+				// Already initialized in aCallocA
+				//memset(map[i].block_mob_count, 0, size);
 
 
 				uidb_put(map_db, (unsigned int)map[i].index, &map[i]);
 				uidb_put(map_db, (unsigned int)map[i].index, &map[i]);
 
 
@@ -3129,20 +3124,15 @@ int parse_console(char *buf) {
 	int m, n;
 	int m, n;
 	struct map_session_data *sd;
 	struct map_session_data *sd;
 
 
-	sd = (struct map_session_data*)aCalloc(sizeof(*sd), 1);
+	sd = (struct map_session_data*)aCalloc(sizeof(struct map_session_data), 1);
 
 
 	sd->fd = 0;
 	sd->fd = 0;
 	strcpy( sd->status.name , "console");
 	strcpy( sd->status.name , "console");
 
 
-	type = (char *)aMallocA(64);
-	command = (char *)aMallocA(64);
-	map = (char *)aMallocA(64);
-	buf2 = (char *)aMallocA(72);
-
-	memset(type,0,64);
-	memset(command,0,64);
-	memset(map,0,64);
-	memset(buf2,0,72);
+	type = (char *)aCallocA(64,1);
+	command = (char *)aCallocA(64,1);
+	map = (char *)aCallocA(64,1);
+	buf2 = (char *)aCallocA(72,1);
 
 
 	if ( ( n = sscanf(buf, "%[^:]:%[^:]:%99s %d %d[^\n]", type , command , map , &x , &y )) < 5 )
 	if ( ( n = sscanf(buf, "%[^:]:%[^:]:%99s %d %d[^\n]", type , command , map , &x , &y )) < 5 )
 		if ( ( n = sscanf(buf, "%[^:]:%[^\n]", type , command )) < 2 )
 		if ( ( n = sscanf(buf, "%[^:]:%[^\n]", type , command )) < 2 )
@@ -3593,9 +3583,11 @@ void do_final(void) {
 
 
 	ShowStatus("Terminating...\n");
 	ShowStatus("Terminating...\n");
 
 
-	// we probably don't need the cache open at all times 'yet', so this is closed by mapsource_final [celest]
+	//we probably don't need the cache open at all times 'yet', so this is closed by mapsource_final [celest]
 	//map_cache_close();
 	//map_cache_close();
-	grfio_final();
+
+	// We probably don't need the grfio after server bootup 'yet' too. So this is closed near the end of do_init [Lance]
+	//grfio_final();
 
 
 	for (i = 0; i < map_num; i++)
 	for (i = 0; i < map_num; i++)
 		if (map[i].m >= 0)
 		if (map[i].m >= 0)
@@ -3887,6 +3879,8 @@ int do_init(int argc, char *argv[]) {
 	if (battle_config.pk_mode == 1)
 	if (battle_config.pk_mode == 1)
 		ShowNotice("Server is running on '"CL_WHITE"PK Mode"CL_RESET"'.\n");
 		ShowNotice("Server is running on '"CL_WHITE"PK Mode"CL_RESET"'.\n");
 
 
+	grfio_final(); // Unused after reading all maps.
+
 	ShowStatus("Server is '"CL_GREEN"ready"CL_RESET"' and listening on port '"CL_WHITE"%d"CL_RESET"'.\n\n", map_port);
 	ShowStatus("Server is '"CL_GREEN"ready"CL_RESET"' and listening on port '"CL_WHITE"%d"CL_RESET"'.\n\n", map_port);
 
 
 	return 0;
 	return 0;

+ 17 - 18
src/map/npc.c

@@ -284,7 +284,7 @@ int npc_event_export(char *lname,void *data,va_list ap)
 		unsigned char buf[51];
 		unsigned char buf[51];
 		char *p=strchr(lname,':');
 		char *p=strchr(lname,':');
 		// エクスポートされる
 		// エクスポートされる
-		ev=(struct event_data *) aCalloc(sizeof(struct event_data), 1);
+		ev=(struct event_data *) aMalloc(sizeof(struct event_data));
 		if (ev==NULL) {
 		if (ev==NULL) {
 			ShowFatalError("npc_event_export: out of memory !\n");
 			ShowFatalError("npc_event_export: out of memory !\n");
 			exit(1);
 			exit(1);
@@ -459,11 +459,12 @@ int npc_addeventtimer(struct npc_data *nd,int tick,const char *name)
 				ShowError("npc_addeventimer: Event %s does not exists.\n", name);
 				ShowError("npc_addeventimer: Event %s does not exists.\n", name);
 			return 1; //Event does not exists!
 			return 1; //Event does not exists!
 		}
 		}
-		evname =(unsigned char *) aCallocA(NAME_LENGTH, sizeof(char));
+		evname =(unsigned char *) aMallocA(NAME_LENGTH*sizeof(char));
 		if(evname==NULL){
 		if(evname==NULL){
 			ShowFatalError("npc_addeventtimer: out of memory !\n");exit(1);
 			ShowFatalError("npc_addeventtimer: out of memory !\n");exit(1);
 		}
 		}
 		memcpy(evname,name,NAME_LENGTH-1);
 		memcpy(evname,name,NAME_LENGTH-1);
+		evname[NAME_LENGTH-1] = '\0';
 		nd->eventtimer[i]=add_timer(gettick()+tick,
 		nd->eventtimer[i]=add_timer(gettick()+tick,
 			npc_event_timer,nd->bl.id,(int)evname);
 			npc_event_timer,nd->bl.id,(int)evname);
 	}else
 	}else
@@ -1397,7 +1398,7 @@ void npc_addsrcfile (char *name)
 		nsl = nsl->next;
 		nsl = nsl->next;
 	}
 	}
 
 
-	nsl = (struct npc_src_list *) aCalloc (1, sizeof(*nsl) + strlen(name));
+	nsl = (struct npc_src_list *) aMalloc (sizeof(*nsl) + strlen(name));
 	nsl->next = NULL;
 	nsl->next = NULL;
 	strncpy(nsl->name, name, strlen(name) + 1);
 	strncpy(nsl->name, name, strlen(name) + 1);
 	if (npc_src_first == NULL)
 	if (npc_src_first == NULL)
@@ -1704,7 +1705,7 @@ static int npc_skip_script (char *w1,char *w2,char *w3,char *w4,char *first_line
 	unsigned char line[1024];
 	unsigned char line[1024];
 	int curly_count = 0;
 	int curly_count = 0;
 	
 	
-	srcbuf = (unsigned char *)aCallocA(srcsize, sizeof(char));
+	srcbuf = (unsigned char *)aMallocA(srcsize*sizeof(char));
 	if (strchr(first_line, '{')) {
 	if (strchr(first_line, '{')) {
 		strcpy((char *)srcbuf, strchr(first_line, '{'));
 		strcpy((char *)srcbuf, strchr(first_line, '{'));
 		startline = *lines;
 		startline = *lines;
@@ -1746,7 +1747,6 @@ static int npc_parse_script (char *w1,char *w2,char *w3,char *w4,char *first_lin
 	unsigned char line[1024];
 	unsigned char line[1024];
 	int i;
 	int i;
 	struct npc_data *nd;
 	struct npc_data *nd;
-	int evflag = 0;
 	struct dbt *label_db;
 	struct dbt *label_db;
 	char *p;
 	char *p;
 	struct npc_label_list *label_dup = NULL;
 	struct npc_label_list *label_dup = NULL;
@@ -1768,7 +1768,7 @@ static int npc_parse_script (char *w1,char *w2,char *w3,char *w4,char *first_lin
 	if (strcmp(w2, "script") == 0){
 	if (strcmp(w2, "script") == 0){
 		// parsing script with curly
 		// parsing script with curly
 		int curly_count = 0;
 		int curly_count = 0;
-		srcbuf = (unsigned char *)aCallocA(srcsize, sizeof(char));
+		srcbuf = (unsigned char *)aMallocA(srcsize*sizeof(char));
 		if (strchr(first_line, '{')) {
 		if (strchr(first_line, '{')) {
 			strcpy((char *)srcbuf, strchr(first_line, '{'));
 			strcpy((char *)srcbuf, strchr(first_line, '{'));
 			startline = *lines;
 			startline = *lines;
@@ -1834,7 +1834,7 @@ static int npc_parse_script (char *w1,char *w2,char *w3,char *w4,char *first_lin
 		if (xs >= 0) xs = xs * 2 + 1;
 		if (xs >= 0) xs = xs * 2 + 1;
 		if (ys >= 0) ys = ys * 2 + 1;
 		if (ys >= 0) ys = ys * 2 + 1;
 
 
-		if (class_ >= -1) { // -1 NPCs use OnTouch [Lance]
+		if (m >= 0) {
 			for (i = 0; i < ys; i++) {
 			for (i = 0; i < ys; i++) {
 				for (j = 0; j < xs; j++) {
 				for (j = 0; j < xs; j++) {
 					if (map_getcell(m, x - xs/2 + j, y - ys/2 + i, CELL_CHKNOPASS))
 					if (map_getcell(m, x - xs/2 + j, y - ys/2 + i, CELL_CHKNOPASS))
@@ -1852,10 +1852,6 @@ static int npc_parse_script (char *w1,char *w2,char *w3,char *w4,char *first_lin
 		nd->u.scr.ys = 0;
 		nd->u.scr.ys = 0;
 	}
 	}
 
 
-	if (class_ < 0 && m >= 0) {	// イベント型NPC
-		evflag = 1;
-	}
-
 	while ((p = strchr(w3,':'))) {
 	while ((p = strchr(w3,':'))) {
 		if (p[1] == ':') break;
 		if (p[1] == ':') break;
 	}
 	}
@@ -1886,19 +1882,22 @@ static int npc_parse_script (char *w1,char *w2,char *w3,char *w4,char *first_lin
 		nd->eventtimer[i] = -1;
 		nd->eventtimer[i] = -1;
 	if (m >= 0) {
 	if (m >= 0) {
 		nd->n = map_addnpc(m, nd);
 		nd->n = map_addnpc(m, nd);
-		if (class_ >= 0)
-			status_set_viewdata(&nd->bl, nd->class_);
 		status_change_init(&nd->bl);
 		status_change_init(&nd->bl);
 		unit_dataset(&nd->bl);
 		unit_dataset(&nd->bl);
 		nd->ud.dir = dir;
 		nd->ud.dir = dir;
 		map_addblock(&nd->bl);
 		map_addblock(&nd->bl);
-		if (evflag) {	// イベント型
+		// Unused. You can always use On::XXXX events. Have this removed to improve perfomance.
+		/*if (evflag) {	// イベント型
 			struct event_data *ev = (struct event_data *)aCalloc(1, sizeof(struct event_data));
 			struct event_data *ev = (struct event_data *)aCalloc(1, sizeof(struct event_data));
 			ev->nd = nd;
 			ev->nd = nd;
 			ev->pos = 0;
 			ev->pos = 0;
 			strdb_put(ev_db, nd->exname, ev);
 			strdb_put(ev_db, nd->exname, ev);
 		} else {
 		} else {
 			clif_spawn(&nd->bl);
 			clif_spawn(&nd->bl);
+		}*/
+		if (class_ >= 0){
+			status_set_viewdata(&nd->bl, nd->class_);
+			clif_spawn(&nd->bl);
 		}
 		}
 	} else {
 	} else {
 		// we skip map_addnpc, but still add it to the list of ID's
 		// we skip map_addnpc, but still add it to the list of ID's
@@ -1943,7 +1942,7 @@ static int npc_parse_script (char *w1,char *w2,char *w3,char *w4,char *first_lin
 
 
 				// remember the label is max 50 chars + eos; see the strdb_init below
 				// remember the label is max 50 chars + eos; see the strdb_init below
 				// generate the data and insert it
 				// generate the data and insert it
-				ev=(struct event_data *)aCalloc(1,sizeof(struct event_data));
+				ev=(struct event_data *)aMalloc(sizeof(struct event_data));
 				ev->nd=nd;
 				ev->nd=nd;
 				ev->pos=pos;
 				ev->pos=pos;
 				if (strdb_put(ev_db,buf,ev) != NULL) //There was already another event of the same name?
 				if (strdb_put(ev_db,buf,ev) != NULL) //There was already another event of the same name?
@@ -1963,7 +1962,7 @@ static int npc_parse_script (char *w1,char *w2,char *w3,char *w4,char *first_lin
 			struct npc_timerevent_list *te = nd->u.scr.timer_event;
 			struct npc_timerevent_list *te = nd->u.scr.timer_event;
 			int j, k = nd->u.scr.timeramount;
 			int j, k = nd->u.scr.timeramount;
 			if (te == NULL)
 			if (te == NULL)
-				te = (struct npc_timerevent_list *)aCallocA(1,sizeof(struct npc_timerevent_list));
+				te = (struct npc_timerevent_list *)aMallocA(sizeof(struct npc_timerevent_list));
 			else
 			else
 				te = (struct npc_timerevent_list *)aRealloc( te, sizeof(struct npc_timerevent_list) * (k+1) );
 				te = (struct npc_timerevent_list *)aRealloc( te, sizeof(struct npc_timerevent_list) * (k+1) );
 			for (j = 0; j < k; j++){
 			for (j = 0; j < k; j++){
@@ -1997,7 +1996,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, char *fir
 	struct dbt *user_db;
 	struct dbt *user_db;
 	
 	
 	// スクリプトの解析
 	// スクリプトの解析
-	srcbuf = (unsigned char *) aCallocA (srcsize, sizeof(char));
+	srcbuf = (unsigned char *) aMallocA (srcsize*sizeof(char));
 	if (strchr(first_line,'{')) {
 	if (strchr(first_line,'{')) {
 		strcpy(srcbuf, strchr(first_line,'{'));
 		strcpy(srcbuf, strchr(first_line,'{'));
 		startline = *lines;
 		startline = *lines;
@@ -2036,7 +2035,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, char *fir
 		return 1;
 		return 1;
 	}
 	}
 
 
-	p = (char *) aCallocA (50, sizeof(char));
+	p = (char *) aMallocA (50*sizeof(char));
 	strncpy(p, w3, 50);
 	strncpy(p, w3, 50);
 
 
 	user_db = script_get_userfunc_db();
 	user_db = script_get_userfunc_db();

+ 2 - 2
src/map/pc.c

@@ -7106,8 +7106,8 @@ int pc_read_gm_account(int fd)
 	if (gm_account != NULL)
 	if (gm_account != NULL)
 		aFree(gm_account);
 		aFree(gm_account);
 	GM_num = 0;
 	GM_num = 0;
-	gm_account = (struct gm_account *) aCallocA(((RFIFOW(fd,2) - 4) / 5), sizeof(struct gm_account));
-	for (i = 4; i < RFIFOW(fd,2); i = i + 5) {
+	gm_account = (struct gm_account *) aMallocA(((RFIFOW(fd,2) - 4) / 5)*sizeof(struct gm_account));
+	for (i = 4; i < RFIFOW(fd,2); i += 5) {
 		gm_account[GM_num].account_id = RFIFOL(fd,i);
 		gm_account[GM_num].account_id = RFIFOL(fd,i);
 		gm_account[GM_num].level = (int)RFIFOB(fd,i+4);
 		gm_account[GM_num].level = (int)RFIFOB(fd,i+4);
 		//printf("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
 		//printf("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);

+ 37 - 52
src/map/script.c

@@ -2436,7 +2436,7 @@ char* conv_str(struct script_state *st,struct script_data *data)
 	get_val(st,data);
 	get_val(st,data);
 	if(data->type==C_INT){
 	if(data->type==C_INT){
 		char *buf;
 		char *buf;
-		buf=(char *)aCallocA(ITEM_NAME_LENGTH,sizeof(char));
+		buf=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
 		snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
 		snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
 		data->type=C_STR;
 		data->type=C_STR;
 		data->u.str=buf;
 		data->u.str=buf;
@@ -2783,7 +2783,7 @@ int buildin_menu(struct script_state *st)
 			conv_str(st,& (st->stack->stack_data[i]));
 			conv_str(st,& (st->stack->stack_data[i]));
 			len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
 			len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
 		}
 		}
-		buf=(char *)aCallocA(len+1,sizeof(char));
+		buf=(char *)aMallocA((len+1)*sizeof(char));
 		buf[0]=0;
 		buf[0]=0;
 		for(i=st->start+2,len=0;i<st->end;i+=2){
 		for(i=st->start+2,len=0;i<st->end;i+=2){
 			strcat(buf,st->stack->stack_data[i].u.str);
 			strcat(buf,st->stack->stack_data[i].u.str);
@@ -4275,8 +4275,9 @@ char *buildin_getpartyname_sub(int party_id)
 
 
 	if(p!=NULL){
 	if(p!=NULL){
 		char *buf;
 		char *buf;
-		buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
+		buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
 		memcpy(buf, p->name, NAME_LENGTH-1);
 		memcpy(buf, p->name, NAME_LENGTH-1);
+		buf[NAME_LENGTH-1] = '\0';
 		return buf;
 		return buf;
 	}
 	}
 
 
@@ -4343,8 +4344,9 @@ char *buildin_getguildname_sub(int guild_id)
 
 
 	if(g!=NULL){
 	if(g!=NULL){
 		char *buf;
 		char *buf;
-		buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
+		buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
 		memcpy(buf, g->name, NAME_LENGTH-1);
 		memcpy(buf, g->name, NAME_LENGTH-1);
+		buf[NAME_LENGTH-1] = '\0';
 		return buf;
 		return buf;
 	}
 	}
 	return NULL;
 	return NULL;
@@ -4372,8 +4374,9 @@ char *buildin_getguildmaster_sub(int guild_id)
 
 
 	if(g!=NULL){
 	if(g!=NULL){
 		char *buf;
 		char *buf;
-		buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
+		buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
 		memcpy(buf, g->master, NAME_LENGTH-1);
 		memcpy(buf, g->master, NAME_LENGTH-1);
+		buf[NAME_LENGTH-1] = '\0';
 		return buf;
 		return buf;
 	}
 	}
 
 
@@ -4416,8 +4419,8 @@ int buildin_getguildmasterid(struct script_state *st)
 int buildin_strcharinfo(struct script_state *st)
 int buildin_strcharinfo(struct script_state *st)
 {
 {
 	struct map_session_data *sd;
 	struct map_session_data *sd;
-	char *buf;
 	int num;
 	int num;
+	char *buf;
 
 
 	sd=script_rid2sd(st);
 	sd=script_rid2sd(st);
 	if (!sd) { //Avoid crashing....
 	if (!sd) { //Avoid crashing....
@@ -4427,9 +4430,7 @@ int buildin_strcharinfo(struct script_state *st)
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	switch(num){
 	switch(num){
 		case 0:
 		case 0:
-			buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
-			memcpy(buf, sd->status.name, NAME_LENGTH-1);
-			push_str(st->stack,C_STR,(unsigned char *) buf);
+			push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->status.name);
 			break;
 			break;
 		case 1:
 		case 1:
 			buf=buildin_getpartyname_sub(sd->status.party_id);
 			buf=buildin_getpartyname_sub(sd->status.party_id);
@@ -4497,7 +4498,7 @@ int buildin_getequipname(struct script_state *st)
 	struct item_data* item;
 	struct item_data* item;
 	char *buf;
 	char *buf;
 
 
-	buf=(char *)aCallocA(64,sizeof(char));
+	buf=(char *)aMallocA(64*sizeof(char));
 	sd=script_rid2sd(st);
 	sd=script_rid2sd(st);
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	num=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	i=pc_checkequip(sd,equip[num-1]);
 	i=pc_checkequip(sd,equip[num-1]);
@@ -5312,7 +5313,7 @@ int buildin_gettimestr(struct script_state *st)
 	fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
 	fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
 	maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
 
 
-	tmpstr=(char *)aCallocA(maxlen+1,sizeof(char));
+	tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
 	strftime(tmpstr,maxlen,fmtstr,localtime(&now));
 	strftime(tmpstr,maxlen,fmtstr,localtime(&now));
 	tmpstr[maxlen]='\0';
 	tmpstr[maxlen]='\0';
 
 
@@ -7146,18 +7147,15 @@ int buildin_getcastlename(struct script_state *st)
 	char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
 	char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
 	struct guild_castle *gc;
 	struct guild_castle *gc;
 	int i;
 	int i;
-	char *buf=NULL;
 	for(i=0;i<MAX_GUILDCASTLE;i++){
 	for(i=0;i<MAX_GUILDCASTLE;i++){
 		if( (gc=guild_castle_search(i)) != NULL ){
 		if( (gc=guild_castle_search(i)) != NULL ){
 			if(strcmp(mapname,gc->map_name)==0){
 			if(strcmp(mapname,gc->map_name)==0){
-				buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
-				memcpy(buf, gc->castle_name, NAME_LENGTH-1);
 				break;
 				break;
 			}
 			}
 		}
 		}
 	}
 	}
-	if(buf)
-	push_str(st->stack,C_STR,(unsigned char *) buf);
+	if(gc)
+		push_str(st->stack,C_CONSTSTR,(unsigned char *) gc->castle_name);
 	else
 	else
 		push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
 		push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
 	return 0;
 	return 0;
@@ -7709,22 +7707,12 @@ int buildin_strmobinfo(struct script_state *st)
 	switch (num) {
 	switch (num) {
 	case 1:
 	case 1:
 		{
 		{
-			char *buf;
-			buf=(char *) aCallocA(NAME_LENGTH, sizeof(char));
-//			buf=mob_db(class_)->name;
-// for string assignments you would need to go for c++ [Shinomori]
-			memcpy(buf, mob_db(class_)->name, NAME_LENGTH-1);
-			push_str(st->stack,C_STR,(unsigned char *) buf);
+			push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->name);
 			break;
 			break;
 		}
 		}
 	case 2:
 	case 2:
 		{
 		{
-			char *buf;
-			buf=(char *) aCallocA(NAME_LENGTH, sizeof(char));
-//			buf=mob_db(class_).jname;
-// for string assignments you would need to go for c++ [Shinomori]
-			memcpy(buf,mob_db(class_)->jname, NAME_LENGTH-1);
-			push_str(st->stack,C_STR,(unsigned char *) buf);
+			push_str(st->stack,C_CONSTSTR,(unsigned char *) mob_db(class_)->jname);
 			break;
 			break;
 		}
 		}
 	case 3:
 	case 3:
@@ -7820,9 +7808,9 @@ int buildin_getitemname(struct script_state *st)
 		push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
 		push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
 		return 0;
 		return 0;
 	}
 	}
-	item_name=(char *)aCallocA(ITEM_NAME_LENGTH,sizeof(char));
+	item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
 
 
-	memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH-1);
+	memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
 	push_str(st->stack,C_STR,(unsigned char *) item_name);
 	push_str(st->stack,C_STR,(unsigned char *) item_name);
 	return 0;
 	return 0;
 }
 }
@@ -7936,7 +7924,7 @@ int buildin_petskillbonus(struct script_state *st)
 		if (pd->bonus->timer != -1)
 		if (pd->bonus->timer != -1)
 			delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
 			delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
 	} else //init
 	} else //init
-		pd->bonus = (struct pet_bonus *) aCalloc(1, sizeof(struct pet_bonus));
+		pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
 
 
 	pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
@@ -7982,10 +7970,10 @@ int buildin_petloot(struct script_state *st)
 		aFree(pd->loot->item);
 		aFree(pd->loot->item);
 	}
 	}
 	else
 	else
-		pd->loot = (struct pet_loot *)aCalloc(1, sizeof(struct pet_loot));
+		pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
 
 
 	pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
 	pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
-	memset(pd->loot->item,0,max * sizeof(struct item));
+	//memset(pd->loot->item,0,max * sizeof(struct item));
 	
 	
 	pd->loot->max=max;
 	pd->loot->max=max;
 	pd->loot->count = 0;
 	pd->loot->count = 0;
@@ -8230,7 +8218,7 @@ int buildin_petrecovery(struct script_state *st)
 		if (pd->recovery->timer != -1)
 		if (pd->recovery->timer != -1)
 			delete_timer(pd->recovery->timer, pet_recovery_timer);
 			delete_timer(pd->recovery->timer, pet_recovery_timer);
 	} else //Init
 	} else //Init
-		pd->recovery = (struct pet_recovery *)aCalloc(1, sizeof(struct pet_recovery));
+		pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
 		
 		
 	pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
@@ -8263,7 +8251,7 @@ int buildin_petheal(struct script_state *st)
 				delete_timer(pd->s_skill->timer, pet_heal_timer);
 				delete_timer(pd->s_skill->timer, pet_heal_timer);
 		}
 		}
 	} else //init memory
 	} else //init memory
-		pd->s_skill = (struct pet_skill_support *) aCalloc(1, sizeof(struct pet_skill_support)); 
+		pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); 
 	
 	
 	pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
 	pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
 	//Use the lv as the amount to heal
 	//Use the lv as the amount to heal
@@ -8295,7 +8283,7 @@ int buildin_petskillattack(struct script_state *st)
 
 
 	pd=sd->pd;
 	pd=sd->pd;
 	if (pd->a_skill == NULL)
 	if (pd->a_skill == NULL)
-		pd->a_skill = (struct pet_skill_attack *)aCalloc(1, sizeof(struct pet_skill_attack));
+		pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
 				
 				
 	pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
@@ -8320,7 +8308,7 @@ int buildin_petskillattack2(struct script_state *st)
 
 
 	pd=sd->pd;
 	pd=sd->pd;
 	if (pd->a_skill == NULL)
 	if (pd->a_skill == NULL)
-		pd->a_skill = (struct pet_skill_attack *)aCalloc(1, sizeof(struct pet_skill_attack));
+		pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
 				
 				
 	pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
@@ -8354,7 +8342,7 @@ int buildin_petskillsupport(struct script_state *st)
 				delete_timer(pd->s_skill->timer, pet_heal_timer);
 				delete_timer(pd->s_skill->timer, pet_heal_timer);
 		}
 		}
 	} else //init memory
 	} else //init memory
-		pd->s_skill = (struct pet_skill_support *) aCalloc(1, sizeof(struct pet_skill_support)); 
+		pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); 
 	
 	
 	pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
 	pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
 	pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
@@ -8584,11 +8572,8 @@ int buildin_getpetinfo(struct script_state *st)
 				break;
 				break;
 			case 2:
 			case 2:
 				if(sd->pet.name)
 				if(sd->pet.name)
-				{	//Shamelessly copied from strcharinfo() [Skotlex]
-					char *buf;
-					buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
-					memcpy(buf, sd->pet.name, NAME_LENGTH-1);
-					push_str(st->stack,C_STR,(unsigned char *) buf);
+				{
+					push_str(st->stack,C_CONSTSTR,(unsigned char *) sd->pet.name);
 				}
 				}
 				else
 				else
 					push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
 					push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
@@ -8674,7 +8659,7 @@ int buildin_select(struct script_state *st)
 			conv_str(st,& (st->stack->stack_data[i]));
 			conv_str(st,& (st->stack->stack_data[i]));
 			len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
 			len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
 		}
 		}
-		buf=(char *)aCalloc(len+1,sizeof(char));
+		buf=(char *)aMalloc((len+1)*sizeof(char));
 		buf[0]=0;
 		buf[0]=0;
 		for(i=st->start+2,len=0;i<st->end;i++){
 		for(i=st->start+2,len=0;i<st->end;i++){
 			strcat(buf,st->stack->stack_data[i].u.str);
 			strcat(buf,st->stack->stack_data[i].u.str);
@@ -8937,7 +8922,7 @@ int buildin_getsavepoint(struct script_state *st)
 	y=sd->status.save_point.y;
 	y=sd->status.save_point.y;
 	switch(type){
 	switch(type){
 		case 0:
 		case 0:
-			mapname=(char *) aCallocA(MAP_NAME_LENGTH+1, sizeof(char));
+			mapname=(char *) aMallocA((MAP_NAME_LENGTH+1)*sizeof(char));
 			memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
 			memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
 			mapname[MAP_NAME_LENGTH]='\0';
 			mapname[MAP_NAME_LENGTH]='\0';
 			push_str(st->stack,C_STR,(unsigned char *) mapname);
 			push_str(st->stack,C_STR,(unsigned char *) mapname);
@@ -9761,7 +9746,7 @@ int buildin_escape_sql(struct script_state *st) {
 	char *t_query, *query;
 	char *t_query, *query;
 	query = conv_str(st,& (st->stack->stack_data[st->start+2]));
 	query = conv_str(st,& (st->stack->stack_data[st->start+2]));
 	
 	
-	t_query = aCallocA(strlen(query)*2+1,sizeof(char));
+	t_query = aMallocA((strlen(query)*2+1)*sizeof(char));
 	jstrescapecpy(t_query,query);
 	jstrescapecpy(t_query,query);
 	push_str(st->stack,C_STR,(unsigned char *)t_query);
 	push_str(st->stack,C_STR,(unsigned char *)t_query);
 	return 0;
 	return 0;
@@ -10592,8 +10577,8 @@ void op_add(struct script_state* st)
 		st->stack->stack_data[st->stack->sp-1].u.num += st->stack->stack_data[st->stack->sp].u.num;
 		st->stack->stack_data[st->stack->sp-1].u.num += st->stack->stack_data[st->stack->sp].u.num;
 	} else { // ss‚Ì—\’è
 	} else { // ss‚Ì—\’è
 		char *buf;
 		char *buf;
-		buf=(char *)aCallocA(strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
-				strlen(st->stack->stack_data[st->stack->sp].u.str)+1,sizeof(char));
+		buf=(char *)aMallocA((strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
+				strlen(st->stack->stack_data[st->stack->sp].u.str)+1)*sizeof(char));
 		strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
 		strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
 		strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
 		strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
 		if(st->stack->stack_data[st->stack->sp-1].type==C_STR) 
 		if(st->stack->stack_data[st->stack->sp-1].type==C_STR) 
@@ -11072,7 +11057,7 @@ int run_script(unsigned char *script,int pos,int rid,int oid)
 		sd->npc_scriptstate = 0;
 		sd->npc_scriptstate = 0;
 	} else {
 	} else {
 		// the script is different, make new script_state and stack
 		// the script is different, make new script_state and stack
-		st.stack = aCalloc (1, sizeof(struct script_stack));
+		st.stack = aMalloc (sizeof(struct script_stack));
 		st.stack->sp = 0;
 		st.stack->sp = 0;
 		st.stack->sp_max = 64;
 		st.stack->sp_max = 64;
 		st.stack->stack_data = (struct script_data *) aCalloc (st.stack->sp_max,sizeof(st.stack->stack_data[0]));
 		st.stack->stack_data = (struct script_data *) aCalloc (st.stack->sp_max,sizeof(st.stack->stack_data[0]));
@@ -11194,7 +11179,7 @@ int mapreg_setregstr(int num,const char *str)
 		mapreg_dirty=1;
 		mapreg_dirty=1;
 		return 0;
 		return 0;
 	}
 	}
-	p=(char *)aCallocA(strlen(str)+1, sizeof(char));
+	p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
 	strcpy(p,str);
 	strcpy(p,str);
 	
 	
 	if (idb_put(mapregstr_db,num,p))
 	if (idb_put(mapregstr_db,num,p))
@@ -11236,7 +11221,7 @@ static int script_load_mapreg(void)
 				ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
 				ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
 				continue;
 				continue;
 			}
 			}
-			p=(char *)aCallocA(strlen(buf2) + 1,sizeof(char));
+			p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
 			strcpy(p,buf2);
 			strcpy(p,buf2);
 			s= add_str((unsigned char *) buf1);
 			s= add_str((unsigned char *) buf1);
 			idb_put(mapregstr_db,(i<<24)|s,p);
 			idb_put(mapregstr_db,(i<<24)|s,p);
@@ -11277,7 +11262,7 @@ static int script_load_mapreg(void)
 			strcpy(buf1,sql_row[0]);
 			strcpy(buf1,sql_row[0]);
 			if( buf1[strlen(buf1)-1]=='$' ){
 			if( buf1[strlen(buf1)-1]=='$' ){
 				i = atoi(sql_row[1]);
 				i = atoi(sql_row[1]);
-				p=(char *)aCallocA(strlen(sql_row[2]) + 1,sizeof(char));
+				p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
 				strcpy(p,sql_row[2]);
 				strcpy(p,sql_row[2]);
 				s= add_str((unsigned char *) buf1);
 				s= add_str((unsigned char *) buf1);
 				idb_put(mapregstr_db,(i<<24)|s,p);
 				idb_put(mapregstr_db,(i<<24)|s,p);

+ 4 - 3
src/map/skill.c

@@ -6499,12 +6499,13 @@ struct skill_unit_group *skill_unitsetting( struct block_list *src, int skillid,
 	group->bl_flag= skill_get_unit_bl_target(skillid);
 	group->bl_flag= skill_get_unit_bl_target(skillid);
 	if(skillid==HT_TALKIEBOX ||
 	if(skillid==HT_TALKIEBOX ||
 	   skillid==RG_GRAFFITI){
 	   skillid==RG_GRAFFITI){
-		group->valstr=(char *) aCallocA(MESSAGE_SIZE, sizeof(char));
+		group->valstr=(char *) aMallocA(MESSAGE_SIZE*sizeof(char));
 		if(group->valstr==NULL){
 		if(group->valstr==NULL){
 			ShowFatalError("skill_castend_map: out of memory !\n");
 			ShowFatalError("skill_castend_map: out of memory !\n");
 			exit(1);
 			exit(1);
 		}
 		}
 		memcpy(group->valstr,talkie_mes,MESSAGE_SIZE-1);
 		memcpy(group->valstr,talkie_mes,MESSAGE_SIZE-1);
+		group->valstr[MESSAGE_SIZE-1] = '\0';
 	}
 	}
 
 
 	//Why redefine local variables when the ones of the function can be reused? [Skotlex]
 	//Why redefine local variables when the ones of the function can be reused? [Skotlex]
@@ -9374,9 +9375,9 @@ struct skill_unit_group *skill_initunitgroup(struct block_list *src,
 	group->group_id=skill_unit_group_newid++;
 	group->group_id=skill_unit_group_newid++;
 	if(skill_unit_group_newid<=0)
 	if(skill_unit_group_newid<=0)
 		skill_unit_group_newid = MAX_SKILL_DB;
 		skill_unit_group_newid = MAX_SKILL_DB;
-	group->unit=(struct skill_unit *)aCalloc(count,sizeof(struct skill_unit));
+	group->unit=(struct skill_unit *)aMalloc(count*sizeof(struct skill_unit));
 	group->unit_count=count;
 	group->unit_count=count;
-	group->val1=group->val2=0;
+	group->val1=group->val2=group->val3=0;
 	group->skill_id=skillid;
 	group->skill_id=skillid;
 	group->skill_lv=skilllv;
 	group->skill_lv=skilllv;
 	group->unit_id=unit_id;
 	group->unit_id=unit_id;