[gparted] Fix bug when copying huge NTFS partition never finishes (#575324)



commit 260e0ea1902e066bfe233e4a505ae800755572bc
Author: Curtis Gedak <gedakc gmail com>
Date:   Mon Mar 1 13:56:05 2010 -0700

    Fix bug when copying huge NTFS partition never finishes (#575324)
    
    Improved logic in cleanup_cursor method to minimize the number of
    string erase operations performed.
    
    Previously when the NTFS copy finished, GParted would take an
    exceptionally long time to clean up the output.  This was due to
    the huge number of small string erase operations performed on a
    extremely large string.

 src/Utils.cc |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/Utils.cc b/src/Utils.cc
index 6c5d0f5..2359766 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -386,13 +386,21 @@ Glib::ustring Utils::cleanup_cursor( const Glib::ustring & text )
 			str .erase( index, 1 ) ;
 	}
 
-	//remove carriage return and line up to previous line feed.  Used in ntfsclone output.
+	//Remove carriage return and line up to previous line feed.  Used in ntfsclone output.
 	//NOTE:  Normal linux line end is line feed.  DOS uses CR + LF.
-	for ( unsigned int index1 = str .find( "\r") ; index1 < str .length() ; index1 = str .find( "\r" ) ) {
-		if ( str .at(index1 + 1) != '\n') { //Only process if next character is not a LF
+	for ( unsigned int index1 = str .find( "\r") ; index1 < str .length() ; index1 = str .find( "\r" ) )
+	{
+		//Only process if next character is not a LF.
+		if ( str .at(index1 + 1) != '\n')
+		{
+			//find point to start erase from.
 			unsigned int index2 = str .rfind( "\n", index1 ) ;
-			if ( index2 <= index1 )
-				str .erase( index2 + 1, index1 - index2 ) ;
+			//find end point to erase up to.
+			unsigned int index3 = str .find( "\n", index1 ) ;
+			unsigned int index4 = str .rfind( "\r", index3 ) ;
+			//perform erase if indices are valid
+			if ( ( index2 <= index1 ) && ( index4 > index2 ) && ( index4 < str .length() ) )
+				str .erase( index2 + 1, index4 - index2 ) ;
 		}
 	}
 	return str;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]