summaryrefslogtreecommitdiff
path: root/src/map/npc.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-12-22 05:27:03 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-12-22 05:27:03 +0000
commit34f200c644ba8598448e20f4aa69a504e55d3c8f (patch)
treea812ecfcfad219d17855da956578b7ad83c88aa2 /src/map/npc.c
parent1d96525d00110de78f02decfd31f106f99ce9c73 (diff)
downloadhercules-34f200c644ba8598448e20f4aa69a504e55d3c8f.tar.gz
hercules-34f200c644ba8598448e20f4aa69a504e55d3c8f.tar.bz2
hercules-34f200c644ba8598448e20f4aa69a504e55d3c8f.tar.xz
hercules-34f200c644ba8598448e20f4aa69a504e55d3c8f.zip
- Change strncpy to memcpy when parsing switches in the script engine since it's guaranteed to be a word of that size (skip_word).
- Made scriptlabel_db duplicate the key. When str_buf is reallocated, the keys in scriptlabel_db could become invalid, causing a crash in npc_convertlabel_db. ( removed the readded >=0x81 equivalent ) - Now npc_convertlabel_db clears scriptlabel_db after using it. - parse_script has an extra parameter options. At the moment it only indicates if scriptlabel_db should be used or not. - Fixed "UINT_MAX undeclared" on systems that don't declare it in limits.h git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9557 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/npc.c')
-rw-r--r--src/map/npc.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/map/npc.c b/src/map/npc.c
index 95cb4b177..4118b79ea 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1725,13 +1725,13 @@ static int npc_parse_shop (char *w1, char *w2, char *w3, char *w4)
*/
int npc_convertlabel_db (DBKey key, void *data, va_list ap)
{
- unsigned char *lname = key.str;
+ const char *lname = (const char*)key.str;
int pos = (int)data;
struct npc_data *nd;
struct npc_label_list *lst;
int num;
- char *p;
- char c;
+ const char *p;
+ int len;
nullpo_retr(0, ap);
nullpo_retr(0, nd = va_arg(ap,struct npc_data *));
@@ -1746,18 +1746,17 @@ int npc_convertlabel_db (DBKey key, void *data, va_list ap)
// In case of labels not terminated with ':', for user defined function support
p = lname;
- while(isalnum(*(unsigned char*)p) || *p == '_') { p++; }
- c = *p;
- *p='\0';
+ while( ISALNUM(*p) || *p == '_' )
+ p++;
+ len = p-lname;
// here we check if the label fit into the buffer
- if (strlen(lname) > 23) {
+ if (len > 23) {
ShowError("npc_parse_script: label name longer than 23 chars! '%s'\n (%s)", lname, current_file);
exit(1);
}
- memcpy(lst[num].name, lname, strlen(lname)+1); //including EOS
-
- *p = c;
+ memcpy(lst[num].name, lname, len);
+ lst[num].name[len]=0;
lst[num].pos = pos;
nd->u.scr.label_list = lst;
nd->u.scr.label_list_num = num+1;
@@ -1868,7 +1867,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
unsigned char line[1024];
int i;
struct npc_data *nd, *dnd;
- struct dbt *label_db;
+ DB label_db;
char *p;
struct npc_label_list *label_dup = NULL;
int label_dupnum = 0;
@@ -1920,7 +1919,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
script = NULL;
} else {
// printf("Ok line %d\n",*lines);
- script = parse_script((unsigned char *) srcbuf, file, startline);
+ script = parse_script(srcbuf, file, startline, SCRIPT_USE_LABEL_DB);
}
if (script == NULL) {
// script parse error?
@@ -2039,6 +2038,7 @@ static int npc_parse_script(char *w1,char *w2,char *w3,char *w4,char *first_line
// ラベルデータのコンバート
label_db = script_get_label_db();
label_db->foreach(label_db, npc_convertlabel_db, nd);
+ label_db->clear(label_db,NULL); // not needed anymore, so clear the db
// もう使わないのでバッファ解放
aFree(srcbuf);
@@ -2156,7 +2156,7 @@ static int npc_parse_function (char *w1, char *w2, char *w3, char *w4, char *fir
ShowError("Missing right curly at file %s, line %d\n",file, *lines);
script = NULL;
} else {
- script = parse_script(srcbuf, file, startline);
+ script = parse_script(srcbuf, file, startline,0);
}
if (script == NULL) {
// script parse error?