[gparted] Fix for implicit assumption that 'FS_UNKNOWN' is last in FILESYSTEMS list



commit 387feb143a8623ce056458c591c5d0f1ee5d8116
Author: Rogier Goossens <goossens rogier gmail com>
Date:   Sat Feb 18 12:27:55 2012 +0100

    Fix for implicit assumption that 'FS_UNKNOWN' is last in FILESYSTEMS list
    
    This assumption was invalidated by commit
    ce9feeda0e9a04da04cec0a1b01512ed68c2495c:
    'Make FileSystem objects in GParted_Core accessible and usable by others'
    
    This patch removes the dependency on this implicit assumption.

 src/GParted_Core.cc |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 1f35b10..fa72231 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -693,11 +693,24 @@ const std::vector<FS> & GParted_Core::get_filesystems() const
 
 const FS & GParted_Core::get_fs( GParted::FILESYSTEM filesystem ) const 
 {
+	unsigned int unknown ;
+
+	unknown = FILESYSTEMS .size() ;
 	for ( unsigned int t = 0 ; t < FILESYSTEMS .size() ; t++ )
+	{
 		if ( FILESYSTEMS[ t ] .filesystem == filesystem )
 			return FILESYSTEMS[ t ] ;
-	
-	return FILESYSTEMS .back() ;
+		else if ( FILESYSTEMS[ t ] .filesystem == FS_UNKNOWN )
+			unknown = t ;
+	}
+
+	if ( unknown == FILESYSTEMS .size() ) {
+		// This shouldn't happen, but just in case...
+		static FS fs;
+		fs .filesystem = FS_UNKNOWN ;
+		return fs ;
+	} else
+		return FILESYSTEMS[ unknown ] ;
 }
 
 std::vector<Glib::ustring> GParted_Core::get_disklabeltypes() 



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