From 3c8999edce9e1f0d5c0dee3ff8311e781d64c684 Mon Sep 17 00:00:00 2001 From: Lance Date: Sun, 27 Aug 2006 06:38:17 +0000 Subject: * Optional macro MEMSET_TURBO for faster low-level memory initializations. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@8499 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/graph.c | 2 +- src/common/grfio.c | 8 +- src/common/malloc.c | 86 +++++++++++++++- src/common/malloc.h | 18 ++++ src/common/mapindex.c | 3 +- src/common/plugins.c | 2 +- src/common/socket.c | 10 +- src/common/socket.h | 2 +- src/common/strlib.c | 4 +- src/common/timer.c | 8 +- src/map/atcommand.c | 278 +++++++++++++++++++++++++------------------------- src/map/battle.c | 16 +-- src/map/charcommand.c | 74 +++++++------- src/map/chrif.c | 8 +- src/map/clif.c | 86 ++++++++-------- src/map/guild.c | 10 +- src/map/irc.c | 54 +++++----- src/map/itemdb.c | 14 +-- src/map/log.c | 2 +- src/map/map.c | 6 +- src/map/mercenary.c | 6 +- src/map/mob.c | 42 ++++---- src/map/npc.c | 18 ++-- src/map/party.c | 12 +-- src/map/path.c | 3 +- src/map/pc.c | 40 ++++---- src/map/pet.c | 12 +-- src/map/script.c | 32 +++--- src/map/skill.c | 40 ++++---- src/map/status.c | 40 ++++---- src/map/storage.c | 4 +- src/map/trade.c | 15 +-- src/map/unit.c | 2 +- 33 files changed, 528 insertions(+), 429 deletions(-) (limited to 'src') diff --git a/src/common/graph.c b/src/common/graph.c index 0a49fa709..4caa830e6 100644 --- a/src/common/graph.c +++ b/src/common/graph.c @@ -71,7 +71,7 @@ void graph_pallet(struct graph* g, int index,unsigned long c) { if(g == NULL || c >= 256) return; if(g->pallet_count <= index) { - memset(g->png_data + 0x29 + 3 * g->pallet_count,0,(index - g->pallet_count) * 3); + malloc_set(g->png_data + 0x29 + 3 * g->pallet_count,0,(index - g->pallet_count) * 3); g->pallet_count = index + 1; } g->png_data[0x29 + index * 3 ] = (unsigned char)((c >> 16) & 0xFF); // R diff --git a/src/common/grfio.c b/src/common/grfio.c index aa677a0e5..6cfc7eeaa 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -169,7 +169,7 @@ static void BitConvert(BYTE *Src,char *BitSwapTable) int lop,prm; BYTE tmp[8]; // *(DWORD*)tmp=*(DWORD*)(tmp+4)=0; - memset(tmp,0,8); + malloc_tsetdword(tmp,0,8); for(lop=0;lop!=64;lop++) { prm = BitSwapTable[lop]-1; if (Src[(prm >> 3) & 7] & BitMaskTable[prm & 7]) { @@ -299,7 +299,7 @@ int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) { z_stream stream; int err; - memset(&stream, 0, sizeof(stream)); + malloc_tsetdword(&stream, 0, sizeof(stream)); stream.next_in = (Bytef*)source; stream.avail_in = (uInt)sourceLen; /* Check for source > 64K on 16-bit machine: */ @@ -479,7 +479,7 @@ static FILELIST* filelist_add(FILELIST *entry) if (filelist_entrys >= filelist_maxentry) { filelist = (FILELIST *)aRealloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST)); - memset(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST)); + malloc_tsetdword(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST)); filelist_maxentry += FILELIST_ADDS; } @@ -949,7 +949,7 @@ char *grfio_alloc_ptr(char *fname) if (gentry_entrys >= gentry_maxentry) { gentry_maxentry += GENTRY_ADDS; gentry_table = (char**)aRealloc(gentry_table, gentry_maxentry * sizeof(char*)); - memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS); + malloc_tsetdword(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS); } len = strlen( fname ); buf = (char*)aMallocA(len + 1); diff --git a/src/common/malloc.c b/src/common/malloc.c index 6eaa994d8..700da0f88 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -4,7 +4,7 @@ #include #include #include -#include "malloc.h" +#include "../common/malloc.h" #include "../common/core.h" #include "../common/showmsg.h" @@ -116,13 +116,15 @@ void aFree_ (void *p, const char *file, int line, const char *func) void* _bcallocA(size_t size, size_t cnt) { void *ret = MALLOCA(size * cnt); - if (ret) memset(ret, 0, size * cnt); + if (ret) //memset(ret, 0, size * cnt); + malloc_set(ret, 0, size*cnt); return ret; } void* _bcalloc(size_t size, size_t cnt) { void *ret = MALLOC(size * cnt); - if (ret) memset(ret, 0, size * cnt); + if (ret) //memset(ret, 0, size * cnt); + malloc_set(ret, 0, size*cnt); return ret; } char* _bstrdup(const char *chr) @@ -325,7 +327,8 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func ) { void* _mcalloc(size_t num, size_t size, const char *file, int line, const char *func ) { void *p = _mmalloc(num * size,file,line,func); - memset(p,0,num * size); + //memset(p,0,num * size); + malloc_set(p,0,num*size); return p; } @@ -683,6 +686,81 @@ static void memmgr_init (void) } #endif +#ifdef MEMSET_TURBO + // This function is practically useless if the the size of the data is + // static. It decides whether to use setword or setdword. + void malloc_set(void *dest, int value, int size) + { + if(size%4 == 0) + malloc_tsetdword(dest, value, size); + else if(size%2 == 0) + malloc_tsetword(dest, (short)value, size); + else + memset(dest, value, (size_t) size); + } + + // Sets 32-bit aligned memory. + void malloc_tsetdword(void *dest, int value, int count){ +#ifdef _WIN32 + _asm + { + mov edx, 0 + mov eax, count + mov ebx, 4 + idiv ebx + mov edi, dest + mov ecx, eax + mov eax, value + rep stosd + } +#else + __asm__("movl $0, %%edx; + movl %1, %%eax; + movl $4, %%ebx; + idivl %%ebx; + movl %0, %%edi; + movl %%eax, %%ecx; + movl %2, %%eax; + rep; + stosd;" + : + : "g" (dest), "g" (count), "g" (value) + : "edx", "eax", "ebx", "edi", "ecx" + ); +#endif + } + + // Sets 16-bit aligned memory. + void malloc_tsetword(void *dest, short value, int count){ +#ifdef _WIN32 + _asm + { + mov edx, 0 + mov eax, count + mov ebx, 2 + idiv ebx + mov edi, dest + mov ecx, eax + mov ax, value + rep stosw + } +#else + __asm__("movl $0, %%edx; + movl %1, %%eax; + movl $2, %%ebx; + idivl %%ebx; + movl %0, %%edi; + movl %%eax, %%ecx; + movw %2, %%ax; + rep; + stosw;" + : + : "g" (dest), "g" (count), "g" (value) + : "edx", "eax", "ebx", "edi", "ecx", "ax" + ); +#endif + } +#endif /*====================================== * Initialise diff --git a/src/common/malloc.h b/src/common/malloc.h index e9dbb9d44..d3df667a6 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -4,6 +4,8 @@ #ifndef _MALLOC_H_ #define _MALLOC_H_ +//#define MEMSET_TURBO + #ifndef __NETBSD__ #if __STDC_VERSION__ < 199901L # if __GNUC__ >= 2 @@ -147,6 +149,22 @@ //////////////////////////////////////////////// unsigned int malloc_usage (void); +#ifndef INLINE + #ifdef _WIN32 + #define INLINE + #else + #define INLINE inline + #endif +#endif +#ifdef MEMSET_TURBO + INLINE void malloc_tsetdword(void *dest, int value, int count); + INLINE void malloc_tsetword(void *dest, short value, int count); + INLINE void malloc_set(void *dest, int value, int size); +#else + #define malloc_tsetdword(x,y,z) memset(x,y,z) + #define malloc_tsetword(x,y,z) memset(x,y,z) + #define malloc_set(x,y,z) memset(x,y,z) +#endif void malloc_init (void); void malloc_final (void); diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 8fbf2da12..0c3faec75 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -3,6 +3,7 @@ #include #include #include "showmsg.h" +#include "../common/malloc.h" #define MAX_MAPINDEX 2000 @@ -70,7 +71,7 @@ void mapindex_init(void) { int index, length; char map_name[1024]; - memset (&indexes, 0, sizeof (indexes)); + malloc_tsetdword (&indexes, 0, sizeof (indexes)); fp=fopen(mapindex_cfgfile,"r"); if(fp==NULL){ ShowFatalError("Unable to read mapindex config file %s!\n", mapindex_cfgfile); diff --git a/src/common/plugins.c b/src/common/plugins.c index fbadca065..a057190b9 100644 --- a/src/common/plugins.c +++ b/src/common/plugins.c @@ -133,7 +133,7 @@ int export_symbol (void *var, int offset) plugin_call_table = (void**)aRealloc(plugin_call_table, max_call_table*sizeof(void*)); // clear the new alloced block - memset(plugin_call_table + call_table_size, 0, (max_call_table-call_table_size)*sizeof(void*)); + malloc_tsetdword(plugin_call_table + call_table_size, 0, (max_call_table-call_table_size)*sizeof(void*)); } // the new table size is delimited by the new element at the end diff --git a/src/common/socket.c b/src/common/socket.c index dc8162ee1..3d7684972 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -424,7 +424,7 @@ int make_listen_port(int port) CREATE(session[fd], struct socket_data, 1); - memset(session[fd],0,sizeof(*session[fd])); + malloc_set(session[fd],0,sizeof(*session[fd])); session[fd]->func_recv = connect_client; return fd; @@ -502,7 +502,7 @@ int make_listen_bind(long ip,int port) CREATE(session[fd], struct socket_data, 1); - memset(session[fd],0,sizeof(*session[fd])); + malloc_set(session[fd],0,sizeof(*session[fd])); session[fd]->func_recv = connect_client; ShowStatus("Open listen port on %d.%d.%d.%d:%i\n", @@ -517,7 +517,7 @@ int console_recieve(int i) { char *buf; CREATE_A(buf, char, 64); - memset(buf,0,sizeof(64)); + malloc_tsetdword(buf,0,sizeof(64)); n = read(0, buf , 64); if ( n < 0 ) @@ -580,7 +580,7 @@ int start_console(void) { if (!session[0]) { // dummy socket already uses fd 0 CREATE(session[0], struct socket_data, 1); } - memset(session[0],0,sizeof(*session[0])); + malloc_set(session[0],0,sizeof(*session[0])); session[0]->func_recv = console_recieve; session[0]->func_console = default_console_parse; @@ -1369,7 +1369,7 @@ void socket_init (void) session[0]->max_rdata = (int)2*rfifo_size; session[0]->max_wdata = (int)2*wfifo_size; - memset (func_parse_table, 0, sizeof(func_parse_table)); + malloc_set (func_parse_table, 0, sizeof(func_parse_table)); func_parse_table[SESSION_RAW].check = default_func_check; func_parse_table[SESSION_RAW].func = default_func_parse; diff --git a/src/common/socket.h b/src/common/socket.h index 158759f9e..ca4b20c91 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -16,7 +16,7 @@ typedef long in_addr_t; #include #endif #include -#include "malloc.h" +#include "../common/malloc.h" #include "cbasetypes.h" extern time_t last_tick; diff --git a/src/common/strlib.c b/src/common/strlib.c index d62bf4f46..8cff2a878 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -8,7 +8,7 @@ #include "strlib.h" #include "utils.h" -#include "malloc.h" +#include "../common/malloc.h" //----------------------------------------------- // string lib. @@ -123,7 +123,7 @@ char *trim(char *str, const char *delim) char *strp = strtok(str,delim); char buf[1024]; char *bufp = buf; - memset(buf,0,sizeof buf); + malloc_tsetdword(buf,0,sizeof buf); while(strp) { strcpy(bufp, strp); diff --git a/src/common/timer.c b/src/common/timer.c index 9baa33e08..1e9ff25aa 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -20,7 +20,7 @@ #include #include "timer.h" -#include "malloc.h" +#include "../common/malloc.h" #include "showmsg.h" // タイマー間隔の最小値。モンスターの大量召還時、多数のクライアント接続時に @@ -137,7 +137,7 @@ static void push_timer_heap(int index) } else { timer_heap_max += 256; timer_heap = (int *) aRealloc( timer_heap, sizeof(int) * timer_heap_max); - memset(timer_heap + (timer_heap_max - 256), 0, sizeof(int) * 256); + malloc_tsetdword(timer_heap + (timer_heap_max - 256), 0, sizeof(int) * 256); } } @@ -210,7 +210,7 @@ int acquire_timer (void) } else { timer_data_max += 256; timer_data = (struct TimerData *) aRealloc( timer_data, sizeof(struct TimerData) * timer_data_max); - memset(timer_data + (timer_data_max - 256), 0, sizeof(struct TimerData) * 256); + malloc_tsetdword(timer_data + (timer_data_max - 256), 0, sizeof(struct TimerData) * 256); } } @@ -383,7 +383,7 @@ int do_timer(unsigned int tick) if (free_timer_list_pos >= free_timer_list_max) { free_timer_list_max += 256; free_timer_list = (int *) aRealloc(free_timer_list, sizeof(int) * free_timer_list_max); - memset(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); + malloc_tsetdword(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); } free_timer_list[free_timer_list_pos++] = i; break; diff --git a/src/map/atcommand.c b/src/map/atcommand.c index c4da0af2f..62fe834c8 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -795,7 +795,7 @@ is_atcommand(const int fd, struct map_session_data* sd, const char* message, int if (!message || !*message) return AtCommand_None; - memset(&info, 0, sizeof(info)); + malloc_set(&info, 0, sizeof(info)); str += strlen(sd->status.name); while (*str && (isspace(*str) || (s_flag == 0 && *str == ':'))) { if (*str == ':') @@ -816,8 +816,8 @@ is_atcommand(const int fd, struct map_session_data* sd, const char* message, int if (type != AtCommand_None) { char command[100]; const char* p = str; - memset(command, '\0', sizeof(command)); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(command, '\0', sizeof(command)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); while (*p && !isspace(*p)) p++; if (p - str >= sizeof(command)) // too long @@ -862,7 +862,7 @@ AtCommandType atcommand(struct map_session_data* sd, const int level, const char if (*p == command_symbol) { // check first char. char command[101]; int i = 0; - memset(info, 0, sizeof(AtCommandInfo)); + malloc_set(info, 0, sizeof(AtCommandInfo)); sscanf(p, "%100s", command); command[sizeof(command)-1] = '\0'; @@ -907,7 +907,7 @@ int msg_config_read(const char *cfgName) { } if ((--called) == 0) - memset(msg_table, 0, sizeof(msg_table[0]) * MAX_MSG); + malloc_tsetdword(msg_table, 0, sizeof(msg_table[0]) * MAX_MSG); while(fgets(line, sizeof(line)-1, fp)) { if (line[0] == '/' && line[1] == '/') continue; @@ -1190,7 +1190,7 @@ int atcommand_commands( int i_cur_cmd,gm_lvl = pc_isGM(sd), count = 0; - memset(cz_line_buff,' ',MESSAGE_SIZE); + malloc_tsetdword(cz_line_buff,' ',MESSAGE_SIZE); cz_line_buff[MESSAGE_SIZE] = 0; clif_displaymessage(fd, msg_txt(273)); @@ -1208,7 +1208,7 @@ int atcommand_commands( { clif_displaymessage(fd,(char*)cz_line_buff); lpcz_cur = cz_line_buff; - memset(cz_line_buff,' ',MESSAGE_SIZE); + malloc_tsetdword(cz_line_buff,' ',MESSAGE_SIZE); cz_line_buff[MESSAGE_SIZE] = 0; } @@ -1291,7 +1291,7 @@ int atcommand_rura( nullpo_retr(-1, sd); - memset(map_name, '\0', sizeof(map_name)); + malloc_tsetdword(map_name, '\0', sizeof(map_name)); if (!message || !*message || (sscanf(message, "%15s %d %d", map_name, &x, &y) < 3 && @@ -1347,7 +1347,7 @@ int atcommand_where( int GM_level, pl_GM_level; nullpo_retr(-1, sd); - memset(atcmd_player_name, '\0', sizeof atcmd_player_name); + malloc_tsetdword(atcmd_player_name, '\0', sizeof atcmd_player_name); if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { clif_displaymessage(fd, "Please, enter a player name (usage: @where )."); @@ -1396,7 +1396,7 @@ int atcommand_jumpto( return -1; } - memset(atcmd_player_name, '\0', sizeof atcmd_player_name); + malloc_tsetdword(atcmd_player_name, '\0', sizeof atcmd_player_name); if (sscanf(message, "%23[^\n]", atcmd_player_name) < 1) return -1; if(strncmp(sd->status.name,atcmd_player_name,NAME_LENGTH)==0) //Yourself mate? Tsk tsk tsk. @@ -1434,7 +1434,7 @@ int atcommand_jump( nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); sscanf(message, "%d %d", &x, &y); @@ -1469,9 +1469,9 @@ int atcommand_who3( nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(match_text, '\0', sizeof(match_text)); - memset(player_name, '\0', sizeof(player_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(match_text, '\0', sizeof(match_text)); + malloc_tsetdword(player_name, '\0', sizeof(player_name)); if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); @@ -1544,9 +1544,9 @@ int atcommand_who2( nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(match_text, '\0', sizeof(match_text)); - memset(player_name, '\0', sizeof(player_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(match_text, '\0', sizeof(match_text)); + malloc_tsetdword(player_name, '\0', sizeof(player_name)); if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); @@ -1616,10 +1616,10 @@ int atcommand_who( nullpo_retr(-1, sd); - memset(temp0, '\0', sizeof(temp0)); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(match_text, '\0', sizeof(match_text)); - memset(player_name, '\0', sizeof(player_name)); + malloc_tsetdword(temp0, '\0', sizeof(temp0)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(match_text, '\0', sizeof(match_text)); + malloc_tsetdword(player_name, '\0', sizeof(player_name)); if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); @@ -1693,8 +1693,8 @@ int atcommand_whomap3( int map_id; char map_name[MAP_NAME_LENGTH]; - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(map_name, '\0', sizeof(map_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(map_name, '\0', sizeof(map_name)); if (!message || !*message) map_id = sd->bl.m; @@ -1753,8 +1753,8 @@ int atcommand_whomap2( nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(map_name, '\0', sizeof(map_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(map_name, '\0', sizeof(map_name)); if (!message || !*message) map_id = sd->bl.m; @@ -1817,10 +1817,10 @@ int atcommand_whomap( nullpo_retr(-1, sd); - memset(temp0, '\0', sizeof(temp0)); - memset(temp1, '\0', sizeof(temp1)); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(map_name, '\0', sizeof(map_name)); + malloc_tsetdword(temp0, '\0', sizeof(temp0)); + malloc_tsetdword(temp1, '\0', sizeof(temp1)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(map_name, '\0', sizeof(map_name)); if (!message || !*message) map_id = sd->bl.m; @@ -1894,11 +1894,11 @@ int atcommand_whogm( nullpo_retr(-1, sd); - memset(temp0, '\0', sizeof(temp0)); - memset(temp1, '\0', sizeof(temp1)); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(match_text, '\0', sizeof(match_text)); - memset(player_name, '\0', sizeof(player_name)); + malloc_tsetdword(temp0, '\0', sizeof(temp0)); + malloc_tsetdword(temp1, '\0', sizeof(temp1)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(match_text, '\0', sizeof(match_text)); + malloc_tsetdword(player_name, '\0', sizeof(player_name)); if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); @@ -1965,9 +1965,9 @@ int atcommand_whozeny( nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(match_text, '\0', sizeof(match_text)); - memset(player_name, '\0', sizeof(player_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(match_text, '\0', sizeof(match_text)); + malloc_tsetdword(player_name, '\0', sizeof(player_name)); if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); @@ -2115,7 +2115,7 @@ int atcommand_speed( nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message) { sprintf(atcmd_output, "Please, enter a speed value (usage: @speed <%d-%d>).", MIN_WALK_SPEED, MAX_WALK_SPEED); @@ -2150,8 +2150,8 @@ int atcommand_charspeed( nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_player_name, '\0', sizeof(atcmd_player_name)); if (!message || !*message || sscanf(message, "%d %23[^\n]", &speed, atcmd_player_name) < 2) { sprintf(atcmd_output, "Please, enter a speed and a player name (usage: @charspeed > ).", MIN_WALK_SPEED, MAX_WALK_SPEED); @@ -2453,7 +2453,7 @@ int atcommand_kill( struct map_session_data *pl_sd; nullpo_retr(-1, sd); - memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); + malloc_tsetdword(atcmd_player_name, '\0', sizeof(atcmd_player_name)); if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { clif_displaymessage(fd, "Please, enter a player name (usage: @kill )."); @@ -2504,7 +2504,7 @@ int atcommand_kami( unsigned long color=0; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if(*(command + 5) != 'c' && *(command + 5) != 'C') { @@ -2605,7 +2605,7 @@ int atcommand_item( int get_count, i; nullpo_retr(-1, sd); - memset(item_name, '\0', sizeof(item_name)); + malloc_tsetdword(item_name, '\0', sizeof(item_name)); if (!message || !*message || sscanf(message, "%99s %d", item_name, &number) < 1) { clif_displaymessage(fd, "Please, enter an item name/id (usage: @item [quantity])."); @@ -2631,7 +2631,7 @@ int atcommand_item( for (i = 0; i < number; i += get_count) { // if not pet egg if (!pet_create_egg(sd, item_id)) { - memset(&item_tmp, 0, sizeof(item_tmp)); + malloc_set(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = item_id; item_tmp.identify = 1; @@ -2666,7 +2666,7 @@ int atcommand_item2( int loop, get_count, i; nullpo_retr(-1, sd); - memset(item_name, '\0', sizeof(item_name)); + malloc_tsetdword(item_name, '\0', sizeof(item_name)); if (!message || !*message || sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9) { clif_displaymessage(fd, "Please, enter all informations (usage: @item2 "); @@ -2702,7 +2702,7 @@ int atcommand_item2( refine = attr = 0; } for (i = 0; i < loop; i++) { - memset(&item_tmp, 0, sizeof(item_tmp)); + malloc_set(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = item_id; item_tmp.identify = identify; item_tmp.refine = refine; @@ -2895,7 +2895,7 @@ int atcommand_help( FILE* fp; nullpo_retr(-1, sd); - memset(buf, '\0', sizeof(buf)); + malloc_tsetdword(buf, '\0', sizeof(buf)); if ((fp = fopen(help_txt, "r")) != NULL) { clif_displaymessage(fd, msg_txt(26)); /* Help commands: */ @@ -2936,7 +2936,7 @@ int atcommand_help2( FILE* fp; nullpo_retr(-1, sd); - memset(buf, '\0', sizeof(buf)); + malloc_tsetdword(buf, '\0', sizeof(buf)); if ((fp = fopen(help2_txt, "r")) != NULL) { clif_displaymessage(fd, msg_txt(26)); /* Help commands: */ @@ -2976,7 +2976,7 @@ int atcommand_gm( char password[100]; nullpo_retr(-1, sd); - memset(password, '\0', sizeof(password)); + malloc_tsetdword(password, '\0', sizeof(password)); if (!message || !*message || sscanf(message, "%99[^\n]", password) < 1) { clif_displaymessage(fd, "Please, enter a password (usage: @gm )."); @@ -3125,7 +3125,7 @@ int atcommand_model( int hair_style = 0, hair_color = 0, cloth_color = 0; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) { sprintf(atcmd_output, "Please, enter at least a value (usage: @model ).", @@ -3168,7 +3168,7 @@ int atcommand_dye(const int fd, struct map_session_data* sd, const char* command int cloth_color = 0; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) { sprintf(atcmd_output, "Please, enter a clothes color (usage: @dye/@ccolor ).", MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); @@ -3196,7 +3196,7 @@ int atcommand_hair_style(const int fd, struct map_session_data* sd, const char* int hair_style = 0; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) { sprintf(atcmd_output, "Please, enter a hair style (usage: @hairstyle/@hstyle ).", MIN_HAIR_STYLE, MAX_HAIR_STYLE); @@ -3243,7 +3243,7 @@ int atcommand_hair_color(const int fd, struct map_session_data* sd, const char* int hair_color = 0; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) { sprintf(atcmd_output, "Please, enter a hair color (usage: @haircolor/@hcolor ).", MIN_HAIR_COLOR, MAX_HAIR_COLOR); @@ -3315,8 +3315,8 @@ int atcommand_go( return 0; } - memset(map_name, '\0', sizeof(map_name)); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(map_name, '\0', sizeof(map_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); // get the number town = atoi(message); @@ -3469,9 +3469,9 @@ int atcommand_monster( short mx, my; nullpo_retr(-1, sd); - memset(name, '\0', sizeof(name)); - memset(monster, '\0', sizeof(monster)); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(name, '\0', sizeof(name)); + malloc_tsetdword(monster, '\0', sizeof(monster)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message) { clif_displaymessage(fd, msg_txt(80)); // Give a display name and monster name/id please. @@ -3728,7 +3728,7 @@ void atcommand_killmonster_sub( if (!sd) return; - memset(map_name, '\0', sizeof(map_name)); + malloc_tsetdword(map_name, '\0', sizeof(map_name)); if (!message || !*message || sscanf(message, "%15s", map_name) < 1) map_id = sd->bl.m; @@ -3786,7 +3786,7 @@ int atcommand_refine( int count; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message || sscanf(message, "%d %d", &position, &refine) < 2) { clif_displaymessage(fd, "Please, enter a position and a amount (usage: @refine <+/- amount>)."); @@ -3859,8 +3859,8 @@ int atcommand_produce( struct item tmp_item; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(item_name, '\0', sizeof(item_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(item_name, '\0', sizeof(item_name)); if (!message || !*message || sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1) { clif_displaymessage(fd, "Please, enter at least an item name/id (usage: @produce <# of very's>)."); @@ -3881,7 +3881,7 @@ int atcommand_produce( attribute = ATTRIBUTE_NORMAL; if (star < MIN_STAR || star > MAX_STAR) star = 0; - memset(&tmp_item, 0, sizeof tmp_item); + malloc_set(&tmp_item, 0, sizeof tmp_item); tmp_item.nameid = item_id; tmp_item.amount = 1; tmp_item.identify = 1; @@ -3917,7 +3917,7 @@ void atcommand_memo_sub(struct map_session_data* sd) { if (!sd) return; - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); clif_displaymessage(sd->fd, "Your actual memo positions are (except respawn point):"); for (i = MIN_PORTAL_MEMO; i <= MAX_PORTAL_MEMO; i++) { @@ -3942,7 +3942,7 @@ int atcommand_memo( int position = 0; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message || sscanf(message, "%d", &position) < 1) atcommand_memo_sub(sd); @@ -3985,7 +3985,7 @@ int atcommand_gat( int y; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); for (y = 2; y >= -2; y--) { sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", @@ -4215,7 +4215,7 @@ int atcommand_param( status[4] = &sd->status.dex; status[5] = &sd->status.luk; - memset(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) { sprintf(atcmd_output, "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>)."); @@ -4543,7 +4543,7 @@ atcommand_recall( return -1; } - memset(atcmd_player_name, '\0', sizeof atcmd_player_name); + malloc_tsetdword(atcmd_player_name, '\0', sizeof atcmd_player_name); if(sscanf(message, "%23[^\n]", atcmd_player_name) < 1) return -1; if(strncmp(sd->status.name,atcmd_player_name,NAME_LENGTH)==0) @@ -4585,7 +4585,7 @@ int atcommand_revive( struct map_session_data *pl_sd; nullpo_retr(-1, sd); - memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); + malloc_tsetdword(atcmd_player_name, '\0', sizeof(atcmd_player_name)); if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { clif_displaymessage(fd, "Please, enter a player name (usage: @revive )."); @@ -4618,7 +4618,7 @@ int atcommand_char_block( { nullpo_retr(-1, sd); - memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); + malloc_tsetdword(atcmd_player_name, '\0', sizeof(atcmd_player_name)); if (!message || !*message || sscanf(message, "%99[^\n]", atcmd_player_name) < 1) { clif_displaymessage(fd, "Please, enter a player name (usage: @charblock/@block )."); @@ -4664,8 +4664,8 @@ int atcommand_char_ban( int year, month, day, hour, minute, second, value; nullpo_retr(-1, sd); - memset(atcmd_output, '\0', sizeof(atcmd_output)); - memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); + malloc_tsetdword(atcmd_output, '\0', sizeof(atcmd_output)); + malloc_tsetdword(atcmd_player_name, '\0', sizeof(atcmd_player_name)); if (!message || !*message || sscanf(message, "%s %99[^\n]", atcmd_output, atcmd_player_name) < 2) { clif_displaymessage(fd, "Please, enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish