[gparted] Successfully read kernel versions with only 2 components



commit a4b82a93053d9482dd6d126820b97ddec8563013
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Dec 3 21:44:26 2013 +0000

    Successfully read kernel versions with only 2 components
    
    When the kernel version as stated in /proc/version did not have at least
    three numbers separated by periods, the version would fail to be read.
    Sample /proc/version to demonstrate problem:
    
        Linux version 3.10-3-686-pae ...
    
    The Linux kernel will always have a major number and a minor number
    separated by a period.  There is likely also a patch version number too
    that would be preceded by a period.  This enhancement will read 2 and 3
    component Linux kernel versions.

 src/Utils.cc |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/src/Utils.cc b/src/Utils.cc
index 2b3ad4a..80e2e7f 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -724,11 +724,11 @@ Byte_Value Utils::ceil_size( Byte_Value value, Byte_Value rounding_size )
 bool Utils::get_kernel_version( int & major_ver, int & minor_ver, int & patch_ver )
 {
        static bool read_file = false ;
-       static int read_major_ver = -1 ;
-       static int read_minor_ver = -1 ;
-       static int read_patch_ver = -1 ;
+       static int read_major_ver = 0 ;
+       static int read_minor_ver = 0 ;
+       static int read_patch_ver = 0 ;
+       static bool success = false ;
 
-       bool success = false ;
        if ( ! read_file )
        {
                std::ifstream input( "/proc/version" ) ;
@@ -736,18 +736,18 @@ bool Utils::get_kernel_version( int & major_ver, int & minor_ver, int & patch_ve
                if ( input )
                {
                        getline( input, line ) ;
-                       sscanf( line .c_str(), "Linux version %d.%d.%d",
-                               &read_major_ver, &read_minor_ver, &read_patch_ver ) ;
+                       int assigned = sscanf( line .c_str(), "Linux version %d.%d.%d",
+                                              &read_major_ver, &read_minor_ver, &read_patch_ver ) ;
+                       success = ( assigned >= 2 ) ;  //At least 2 kernel version components read
                        input .close() ;
                }
                read_file = true ;
        }
-       if ( read_major_ver > -1 && read_minor_ver > -1 && read_patch_ver > -1 )
+       if ( success )
        {
                major_ver = read_major_ver ;
                minor_ver = read_minor_ver ;
                patch_ver = read_patch_ver ;
-               success = true ;
        }
        return success ;
 }


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