[Box Backup-commit] COMMIT r2786 - box/invisnet/vs2010/0.11/lib/common

subversion at boxbackup.org subversion at boxbackup.org
Sat Oct 9 05:17:17 BST 2010


Author: invisnet
Date: 2010-10-09 05:17:16 +0100 (Sat, 09 Oct 2010)
New Revision: 2786

Modified:
   box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp
Log:
Ignore Windows-style INI headers; fix the parser to stay within bounds

Modified: box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp	2010-10-07 13:51:24 UTC (rev 2785)
+++ box/invisnet/vs2010/0.11/lib/common/FdGetLine.cpp	2010-10-09 04:17:16 UTC (rev 2786)
@@ -165,11 +165,25 @@
 	{
 		return r;
 	}
+	// Skip Windows INI style headers
+	// r might be empty so can't use r[0]
+	else if(r.c_str()[0] == '[')
+	{
+		r.clear();
+		return r;
+	}
 	else
 	{
+		// Remove whitespace
+		int size = r.size();
+		int begin = 0;
+		while(begin < size && iw(r[begin]))
+		{
+			begin++;
+		}
+		
 		// Check for comment char, but char before must be whitespace
-		int end = 0;
-		int size = r.size();
+		int end = begin;
 		while(end < size)
 		{
 			if(r[end] == '#' && (end == 0 || (iw(r[end-1]))))
@@ -179,17 +193,7 @@
 			end++;
 		}
 		
-		// Remove whitespace
-		int begin = 0;
-		while(begin < size && iw(r[begin]))
-		{
-			begin++;
-		}
-		if(!iw(r[end])) end--;
-		while(end > begin && iw(r[end]))
-		{
-			end--;
-		}
+		for(end--; end > begin && iw(r[end]); end--);
 		
 		// Return a sub string
 		return r.substr(begin, end - begin + 1);




More information about the Boxbackup-commit mailing list