summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt3
-rw-r--r--src/map/script.c140
2 files changed, 40 insertions, 103 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index fc2d325a3..a25e5cdd8 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -3,6 +3,9 @@ Date Added
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.
+2006/08/01
+ * Modified setlabel so that the script engine barks when you are trying to
+ use the same label name as a constant or variable name. [Skotlex]
2006/07/31
* Fixed the subnet 0 mask being reset to 0 when someone goes up on the fame
rankings. [Skotlex]
diff --git a/src/map/script.c b/src/map/script.c
index 8d30e9fd7..3272eb005 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -150,6 +150,7 @@ int run_func(struct script_state *st);
int mapreg_setreg(int num,int val);
int mapreg_setregstr(int num,const char *str);
+static void disp_error_message(const char *mes,unsigned char *pos);
enum {
C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
@@ -423,10 +424,19 @@ static void add_scriptl(int l)
* ラベルを解決する
*------------------------------------------
*/
-void set_label(int l,int pos)
+void set_label(int l,int pos, unsigned char *script_pos)
{
int i,next;
+ if(str_data[l].type==C_INT || str_data[l].type==C_PARAM)
+ { //Prevent overwriting constants values and parameters [Skotlex]
+ disp_error_message("invalid label name",script_pos);
+ return;
+ }
+ if(str_data[l].label!=-1){
+ disp_error_message("dup label ",script_pos);
+ return;
+ }
str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
str_data[l].label=pos;
for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
@@ -863,11 +873,7 @@ unsigned char* parse_curly_close(unsigned char *p) {
// 現在地のラベルを付ける
sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos, p);
if(syntax.curly[pos].flag) {
// default が存在する
@@ -880,11 +886,7 @@ unsigned char* parse_curly_close(unsigned char *p) {
// 終了ラベルを付ける
sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos, p);
syntax.curly_count--;
return p+1;
@@ -955,11 +957,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// 現在地のラベルを付ける
sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos, p);
}
// switch 判定文
p = skip_word(p);
@@ -984,11 +982,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// FALLTHRU 終了後のラベル
sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
}
// 一時変数を消す
sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
@@ -1052,11 +1046,7 @@ unsigned char* parse_syntax(unsigned char *p) {
p++;
sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
// 無条件で次のリンクに飛ばす
sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
@@ -1067,11 +1057,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// default のラベルを付ける
sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
syntax.curly[syntax.curly_count - 1].flag = 1;
syntax.curly[pos].count++;
@@ -1092,11 +1078,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// 現在地のラベル形成する
sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
syntax.curly_count++;
return p;
}
@@ -1129,11 +1111,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// 条件判断開始のラベル形成する
sprintf(label,"__FR%x_J",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
p=skip_space(p);
if(*p == ';') {
@@ -1164,11 +1142,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// 次のループへのラベル形成する
sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
// 次のループに入る時の処理
// for 最後の ')' を ';' として扱うフラグ
@@ -1187,11 +1161,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// ループ開始のラベル付け
sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
return p;
} else if(!strncmp(p,"function",8) && !isalpha(*(p + 8))) {
unsigned char *func_name;
@@ -1232,17 +1202,11 @@ unsigned char* parse_syntax(unsigned char *p) {
// 関数名のラベルを付ける
*p = 0;
l=add_str(func_name);
- if(str_data[l].type == C_NOP) {
+ if(str_data[l].type == C_NOP)
str_data[l].type = C_USERFUNC;
- }
- if(str_data[l].label!=-1){
- *p=c;
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
- strdb_put(scriptlabel_db,func_name,(void*)script_pos); // 外部用label db登録
*p = c;
+ set_label(l,script_pos,p);
+ strdb_put(scriptlabel_db,func_name,(void*)script_pos);
return skip_space(p);
}
}
@@ -1307,11 +1271,7 @@ unsigned char* parse_syntax(unsigned char *p) {
// 条件判断開始のラベル形成する
sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
// 条件が偽なら終了地点に飛ばす
sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
@@ -1362,11 +1322,7 @@ unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
// 現在地のラベルを付ける
sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
syntax.curly[pos].count++;
p = skip_space(p);
@@ -1401,11 +1357,7 @@ unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
// 最終地のラベルを付ける
sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
if(syntax.curly[pos].flag == 1) {
// このifに対するelseじゃないのでポインタの位置は同じ
return p2;
@@ -1420,11 +1372,7 @@ unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
// 現在地のラベル形成する(continue でここに来る)
sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
}
// 条件が偽なら終了地点に飛ばす
@@ -1452,11 +1400,7 @@ unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
// 条件終了地点のラベル形成する
sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
p = skip_space(p);
if(*p != ';') {
disp_error_message("need ';'",p);
@@ -1475,11 +1419,7 @@ unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
// for 終了のラベル付け
sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
syntax.curly_count--;
return p;
} else if(syntax.curly[pos].type == TYPE_WHILE) {
@@ -1492,11 +1432,7 @@ unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
// while 終了のラベル付け
sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
syntax.curly_count--;
return p;
} else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
@@ -1512,11 +1448,7 @@ unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
// 現在地のラベルを付ける
sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
l=add_str(label);
- if(str_data[l].label!=-1){
- disp_error_message("dup label ",p);
- exit(1);
- }
- set_label(l,script_pos);
+ set_label(l,script_pos,p);
syntax.curly_count--;
return p + 1;
} else {
@@ -1714,13 +1646,15 @@ struct script_code* parse_script(unsigned char *src,const char *file,int line)
exit(1);
}
l=add_str(p);
+ /* FIXME: How much does it breaks to not restore skipword(p)=c when an error occurs here?
if(str_data[l].label!=-1){
*skip_word(p)=c;
disp_error_message("dup label ",p);
exit(1);
}
- set_label(l,script_pos);
- strdb_put(scriptlabel_db, p, (void*)script_pos); // 外部用label db登録
+ */
+ set_label(l,script_pos,p);
+ strdb_put(scriptlabel_db, p, (void*)script_pos);
*skip_word(p)=c;
p=tmpp+1;
continue;
@@ -1731,7 +1665,7 @@ struct script_code* parse_script(unsigned char *src,const char *file,int line)
p=skip_space(p);
add_scriptc(C_EOL);
- set_label(LABEL_NEXTLINE,script_pos);
+ set_label(LABEL_NEXTLINE,script_pos,p);
str_data[LABEL_NEXTLINE].type=C_NOP;
str_data[LABEL_NEXTLINE].backpatch=-1;
str_data[LABEL_NEXTLINE].label=-1;