summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-27 05:47:50 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-27 05:47:50 +0000
commit957ecdfbb008733cded26a6dab20c7ac13814f58 (patch)
tree4d639c3e82d23437b54f14ca56bbfcf1bb5d6ffc /src
parent1307b441cd2cdc94bdde1999d48aefb55d91e082 (diff)
downloadhercules-957ecdfbb008733cded26a6dab20c7ac13814f58.tar.gz
hercules-957ecdfbb008733cded26a6dab20c7ac13814f58.tar.bz2
hercules-957ecdfbb008733cded26a6dab20c7ac13814f58.tar.xz
hercules-957ecdfbb008733cded26a6dab20c7ac13814f58.zip
* Corrected description of scope and npc variables in script_commands.txt.
* Made temporary character string variables not have a limited length. (now all temporary string variables don't have limited length) * Made temporary character variables reuse free positions. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11984 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/map/map.c4
-rw-r--r--src/map/map.h2
-rw-r--r--src/map/pc.c54
-rw-r--r--src/map/script.c7
4 files changed, 41 insertions, 26 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 6e8bf4775..4f8984041 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1671,6 +1671,10 @@ int map_quit(struct map_session_data *sd)
}
if(sd->regstr)
{
+ int i;
+ for( i = 0; i < sd->regstr_num; ++i )
+ if( sd->regstr[i].data )
+ aFree(sd->regstr[i].data);
aFree(sd->regstr);
sd->regstr = NULL;
sd->regstr_num = 0;
diff --git a/src/map/map.h b/src/map/map.h
index ecdc72c4f..24b6eb052 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -365,7 +365,7 @@ struct script_reg {
};
struct script_regstr {
int index;
- char data[256];
+ char* data;
};
struct status_change_entry {
diff --git a/src/map/pc.c b/src/map/pc.c
index 959503654..5c5b08a49 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -5898,15 +5898,19 @@ int pc_setreg(struct map_session_data* sd, int reg, int val)
ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
if( i < sd->reg_num )
- // overwrite existing entry
+ {// overwrite existing entry
sd->reg[i].data = val;
- else {
- // insert new entry
+ return 1;
+ }
+
+ ARR_FIND( 0, sd->reg_num, i, sd->reg[i].data == 0 );
+ if( i == sd->regstr_num )
+ {// nothing free, increase size
sd->reg_num++;
RECREATE(sd->reg, struct script_reg, sd->reg_num);
- sd->reg[i].index = reg;
- sd->reg[i].data = val;
}
+ sd->reg[i].index = reg;
+ sd->reg[i].data = val;
return 1;
}
@@ -5939,27 +5943,37 @@ int pc_setregstr(struct map_session_data* sd, int reg, char* str)
ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
if( i < sd->regstr_num )
- {
- if (str && strcmp(str,"")!=0)
- safestrncpy(sd->regstr[i].data, str, sizeof(sd->regstr[i].data));
- else {
- sd->regstr_num--;
- memcpy(&sd->regstr[i], &sd->regstr[sd->regstr_num], sizeof(sd->regstr[0]));
- RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
+ {// found entry, update
+ if( str == NULL || *str == '\0' )
+ {// empty string
+ if( sd->regstr[i].data != NULL )
+ aFree(sd->regstr[i].data);
+ sd->regstr[i].data = NULL;
+ }
+ else if( sd->regstr[i].data )
+ {// recreate
+ size_t len = strlen(str)+1;
+ RECREATE(sd->regstr[i].data, char, len);
+ memcpy(sd->regstr[i].data, str, len*sizeof(char));
+ }
+ else
+ {// create
+ sd->regstr[i].data = aStrdup(str);
}
return 1;
}
- if (!str) return 1;
+ if( str == NULL || *str == '\0' )
+ return 1;// nothing to add, empty string
- sd->regstr_num++;
- RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
- if(sd->regstr==NULL){
- ShowFatalError("out of memory : pc_setreg\n");
- exit(EXIT_FAILURE);
+ ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].data == NULL );
+ if( i == sd->regstr_num )
+ {// nothing free, increase size
+ sd->regstr_num++;
+ RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
}
sd->regstr[i].index = reg;
- safestrncpy(sd->regstr[i].data, str, sizeof(sd->regstr[i].data));
+ sd->regstr[i].data = aStrdup(str);
return 1;
}
@@ -5968,7 +5982,7 @@ int pc_readregistry(struct map_session_data *sd,const char *reg,int type)
{
struct global_reg *sd_reg;
int i,max;
-
+
nullpo_retr(0, sd);
switch (type) {
case 3: //Char reg
diff --git a/src/map/script.c b/src/map/script.c
index b0621aa40..12f9b9313 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2268,11 +2268,8 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, char* name, voi
char* p;
struct linkdb_node** n;
n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars;
- p = linkdb_search(n, (void*)num);
- if (p) {
- linkdb_erase(n, (void*)num);
- aFree(p);
- }
+ p = linkdb_erase(n, (void*)num);
+ if (p) aFree(p);
if (str[0]) linkdb_insert(n, (void*)num, aStrdup(str));
}
return 1;