소스 검색

* Reverted r14525 (introduction of SV_READDB_MAX_FIELDS) because it causes confusion to certain group of users and depends on MAX_LEVEL since r14526.
- Made sv_readdb be able to process any amount of columns instead.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14595 54d463be-8e91-2dee-dedb-b68131a5f0ec

ai4rei 14 년 전
부모
커밋
7502f6c185
2개의 변경된 파일10개의 추가작업 그리고 10개의 파일을 삭제
  1. 2 0
      Changelog-Trunk.txt
  2. 8 10
      src/common/strlib.c

+ 2 - 0
Changelog-Trunk.txt

@@ -1,6 +1,8 @@
 Date	Added
 
 2010/12/16
+	* Reverted r14525 (introduction of SV_READDB_MAX_FIELDS) because it causes confusion to certain group of users and depends on MAX_LEVEL since r14526. [Ai4rei]
+	- Made sv_readdb be able to process any amount of columns instead.
 	* Fixed a mistake in sv_split, causing CR being recognized as EOL character, even when only LF was specified (since r12459). [Ai4rei]
 2010/12/15
 	* Corrected type of second argument of script command 'setbattleflag' from string to number (bugreport:4640, topic:261833, since r5407, related r14577). [Ai4rei]

+ 8 - 10
src/common/strlib.c

@@ -12,7 +12,6 @@
 #include <errno.h>
 
 
-#define SV_READDB_MAX_FIELDS 105
 #define J_MAX_MALLOC_SIZE 65535
 
 // escapes a string in-place (' -> \' , \ -> \\ , % -> _)
@@ -923,18 +922,12 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
 	FILE* fp;
 	int lines = 0;
 	int entries = 0;
-	char* fields[SV_READDB_MAX_FIELDS+1]; // room for SV_READDB_MAX_FIELDS fields ([0] is reserved)
-	int columns;
+	char** fields; // buffer for fields ([0] is reserved)
+	int columns, fields_length;
 	char path[1024], line[1024];
 
 	snprintf(path, sizeof(path), "%s/%s", directory, filename);
 
-	if( maxcols > ARRAYLENGTH(fields)-1 )
-	{
-		ShowError("sv_readdb: Insufficient column storage in parser for file \"%s\" (want %d, have only %d). Increase the capacity in the source code please.\n", path, maxcols, ARRAYLENGTH(fields)-1);
-		return false;
-	}
-
 	// open file
 	fp = fopen(path, "r");
 	if( fp == NULL )
@@ -943,6 +936,10 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
 		return false;
 	}
 
+	// allocate enough memory for the maximum requested amount of columns plus the reserved one
+	fields_length = maxcols+1;
+	fields = aMalloc(fields_length*sizeof(char*));
+
 	// process rows one by one
 	while( fgets(line, sizeof(line), fp) )
 	{
@@ -954,7 +951,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
 		if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
 			continue;
 
-		columns = sv_split(line, strlen(line), 0, delim, fields, ARRAYLENGTH(fields), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
+		columns = sv_split(line, strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
 
 		if( columns < mincols )
 		{
@@ -983,6 +980,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
 		entries++;
 	}
 
+	aFree(fields);
 	fclose(fp);
 	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, path);