From be53cf584b97ae3331d1d211b1c71b740c6aba32 Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Thu, 27 May 2010 10:59:12 -0600 Subject: [PATCH] Fix off by 1 sector math when looking for unallocated space --- src/GParted_Core.cc | 8 ++++---- src/Operation.cc | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 7b175dc0..8faf62ef 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -1229,10 +1229,10 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path, //look for gaps in between for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ ) { - if ( ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end ) > (MEBIBYTE / sector_size) ) + if ( ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end - 1 ) > (MEBIBYTE / sector_size) ) || ( ( partitions[ t + 1 ] .type != TYPE_LOGICAL ) // Only show exactly 1 MiB if following partition is not logical. - && ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end ) == (MEBIBYTE / sector_size) - ) + && ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end - 1 ) == (MEBIBYTE / sector_size) ) + ) ) { partition_temp .sector_start = partitions[ t ] .sector_end +1 ; @@ -1243,7 +1243,7 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path, } //last partition end <---> end - if ( (end - partitions .back() .sector_end ) >= (MEBIBYTE / sector_size) ) + if ( (end - partitions .back() .sector_end) >= (MEBIBYTE / sector_size) ) { partition_temp .sector_start = partitions .back() .sector_end +1 ; partition_temp .sector_end = end ; diff --git a/src/Operation.cc b/src/Operation.cc index afd44678..89170db9 100644 --- a/src/Operation.cc +++ b/src/Operation.cc @@ -71,9 +71,9 @@ void Operation::insert_unallocated( std::vector & partitions, Sector //look for gaps in between for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ ) { - if ( ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end ) > (MEBIBYTE / sector_size) ) + if ( ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end - 1 ) > (MEBIBYTE / sector_size) ) || ( ( partitions[ t + 1 ] .type != TYPE_LOGICAL ) // Only show exactly 1 MiB if following partition is not logical. - && ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end ) == (MEBIBYTE / sector_size) + && ( ( partitions[ t + 1 ] .sector_start - partitions[ t ] .sector_end - 1 ) == (MEBIBYTE / sector_size) ) ) ) {