소스 검색

- Checked and fixed the script engine barking when you try to have a label with the same name as a const.txt defined parameter.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@5415 54d463be-8e91-2dee-dedb-b68131a5f0ec
skotlex 19 년 전
부모
커밋
343577ac3b
3개의 변경된 파일36개의 추가작업 그리고 111개의 파일을 삭제
  1. 2 0
      Changelog-Trunk.txt
  2. 1 2
      src/login_sql/login.c
  3. 33 109
      src/map/script.c

+ 2 - 0
Changelog-Trunk.txt

@@ -5,6 +5,8 @@ IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.  EV
 GOES INTO TRUNK AND WILL BE MERGED INTO STABLE BY VALARIS AND WIZPUTER. -- VALARIS
 
 2006/03/01
+	* Checked and fixed the script engine barking when you try to have a label
+	  with the same name as a const.txt defined parameter. [Skotlex]
 	* Turn Undead and Offensive Resurrection should now work on undead players.
 	  [Skotlex]
 	* Fixed the range checking of Repair weapon [Skotlex]

+ 1 - 2
src/login_sql/login.c

@@ -237,10 +237,9 @@ void read_gm_account(void) {
 				gm_account_db[GM_num].level = atoi(sql_row[1]);
 				GM_num++;
 			}
+			mysql_free_result(sql_res);
 		}
 	}
-
-	mysql_free_result(sql_res);
 }
 
 int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len);

+ 33 - 109
src/map/script.c

@@ -110,6 +110,7 @@ unsigned char* parse_syntax_close(unsigned char *p);
 unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag);
 unsigned char* parse_syntax(unsigned char *p);
 static int parse_syntax_for_flag = 0;
+static void disp_error_message(const char *mes,const unsigned char *pos);
 
 extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
 int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
@@ -926,9 +927,17 @@ static void add_scriptl(int l)
  * ラベルを解決する
  *------------------------------------------
  */
-void set_label(int l,int pos)
+void set_label(int l,int pos, unsigned char *name)
 {
 	int i,next;
+	if (str_data[l].label != -1) {
+		disp_error_message("dup label", name);
+		exit(1);
+	}
+	if(str_data[l].type == C_PARAM) {
+		disp_error_message("invalid label name",name);
+		exit(1);
+	}
 
 	str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
 	str_data[l].label=pos;
@@ -1387,11 +1396,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 が存在する
@@ -1404,11 +1409,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;
@@ -1479,11 +1480,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);
@@ -1508,11 +1505,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);
@@ -1576,11 +1569,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);
@@ -1591,11 +1580,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++;
@@ -1616,11 +1601,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;
 		}
@@ -1653,11 +1634,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);
 
 			if(*p == ';') {
 				// for(;;) のパターンなので必ず真
@@ -1687,11 +1664,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 最後の '(' を ';' として扱うフラグ
@@ -1710,11 +1683,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;
@@ -1755,19 +1724,10 @@ unsigned char* parse_syntax(unsigned char *p) {
 				// 関数名のラベルを付ける
 				*p = 0;
 				l=add_str(func_name);
-				if(str_data[l].type == C_PARAM) {
-					disp_error_message("invalid label name ",p);
-					exit(1);
-				}
 				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);
+				set_label(l,script_pos,&c);
 				strdb_put(scriptlabel_db,func_name,(void*)script_pos);	// 外部用label db登録
 				*p = c;
 				return skip_space(p);
@@ -1834,11 +1794,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);
@@ -1889,11 +1845,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);
@@ -1928,11 +1880,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;
@@ -1947,11 +1895,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);
 		}
 
 		// 条件が偽なら終了地点に飛ばす
@@ -1979,11 +1923,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);
@@ -2002,11 +1942,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) {
@@ -2019,11 +1955,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) {
@@ -2039,11 +1971,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 {
@@ -2161,16 +2089,12 @@ unsigned char* parse_script(unsigned char *src,int line)
 		// labelだけ特殊処理
 		tmpp = skip_space(skip_word(p));
 		if (*tmpp == ':' && !(!strncmp(p,"default",7) && !isalpha(*(p + 7)))) {
-			int l, c;
+			int l;
+			unsigned char c;
 			c = *skip_word(p);
 			*skip_word(p) = 0;
 			l = add_str(p);
-			if (str_data[l].label != -1) {
-				*skip_word(p) = c;
-				disp_error_message("dup label ", p);
-				exit(1);
-			}
-			set_label(l, script_pos);
+			set_label(l, script_pos,&c);
 			strdb_put(scriptlabel_db, p, (void*)script_pos);	// 外部用label db登録
 			*skip_word(p) = c;
 			p = tmpp + 1;
@@ -2182,7 +2106,7 @@ unsigned char* parse_script(unsigned char *src,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;