Fix off by 1 sector math when looking for unallocated space

This commit is contained in:
Curtis Gedak 2010-05-27 10:59:12 -06:00
parent 87e48efe88
commit be53cf584b
2 changed files with 6 additions and 6 deletions

View File

@ -1229,10 +1229,10 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
//look for gaps in between //look for gaps in between
for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ ) 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 ] .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 ; 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 //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_start = partitions .back() .sector_end +1 ;
partition_temp .sector_end = end ; partition_temp .sector_end = end ;

View File

@ -71,9 +71,9 @@ void Operation::insert_unallocated( std::vector<Partition> & partitions, Sector
//look for gaps in between //look for gaps in between
for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ ) 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 ] .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) )
) )
) )
{ {