Prechádzať zdrojové kódy

* Fixed NPCs with closing parenthesis in their name could not be duplicated (bugreport:3235).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14695 54d463be-8e91-2dee-dedb-b68131a5f0ec
ai4rei 14 rokov pred
rodič
commit
1bb6a3d506
2 zmenil súbory, kde vykonal 8 pridanie a 2 odobranie
  1. 1 0
      Changelog-Trunk.txt
  2. 7 2
      src/map/npc.c

+ 1 - 0
Changelog-Trunk.txt

@@ -1,6 +1,7 @@
 Date	Added
 
 2011/02/05
+	* Fixed NPCs with closing parenthesis in their name could not be duplicated (bugreport:3235). [Ai4rei]
 	* Fixed closing 'switch' curly not causing script EOL processing to trigger, leading to the script line after the switch being handled as belonging to the curly-less statement block (bugreport:3273, since r3422). [Ai4rei]
 	* Removed unnecessary getlogincount.pl, mapcheck.sh and mapchecker.sh tools (topic:262934). [Ai4rei]
 2011/02/02

+ 7 - 2
src/map/npc.c

@@ -2263,6 +2263,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
 	char srcname[128];
 	int i;
 	const char* end;
+	size_t length;
 
 	int src_id;
 	int type;
@@ -2270,12 +2271,16 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
 	struct npc_data* dnd;
 
 	end = strchr(start,'\n');
+	length = strlen(w2);
+
 	// get the npc being duplicated
-	if( sscanf(w2,"duplicate(%127[^)])",srcname) != 1 )
-	{
+	if( w2[length-1] != ')' || length <= 11 || length-11 >= sizeof(srcname) )
+	{// does not match 'duplicate(%127s)', name is empty or too long
 		ShowError("npc_parse_script: bad duplicate name in file '%s', line '%d' : %s\n", filepath, strline(buffer,start-buffer), w2);
 		return end;// next line, try to continue
 	}
+	safestrncpy(srcname, w2+10, length-10);
+
 	dnd = npc_name2id(srcname);
 	if( dnd == NULL) {
 		ShowError("npc_parse_script: original npc not found for duplicate in file '%s', line '%d' : %s\n", filepath, strline(buffer,start-buffer), srcname);