[gparted] Use pointer to Partition in Dialog_Base_Partition and derived classes (#759726)



commit 4a6cbcd0f1e6238bdf8c06b592f19538267c6d23
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun Dec 13 14:38:30 2015 +0000

    Use pointer to Partition in Dialog_Base_Partition and derived classes (#759726)
    
    Now use a pointer to the Partition object in Dialog_Base_Partition class
    and derived classes, Dialog_Partition_{Copy,New,Resize_Move}.  This is
    equivalent to how the Partition objects are managed in the Operation and
    derived classes.
    
    The Partition object is allocated and copy constructed in each derived
    classes' set_data() method, called from each constructor and deallocated
    in the destructors.  Considering the remaining Big 3, these classes are
    never copy constructed or copy assigned so provide private definitions
    and no implementations so the compiler enforces this.
    
    Bug 759726 - Implement Partition object polymorphism

 include/Dialog_Base_Partition.h        |    5 +-
 include/Dialog_Partition_Copy.h        |    4 +
 include/Dialog_Partition_New.h         |    6 ++
 include/Dialog_Partition_Resize_Move.h |    4 +
 src/Dialog_Base_Partition.cc           |   99 +++++++++++++----------
 src/Dialog_Partition_Copy.cc           |   22 ++++--
 src/Dialog_Partition_New.cc            |  105 ++++++++++++++----------
 src/Dialog_Partition_Resize_Move.cc    |  139 +++++++++++++++++--------------
 8 files changed, 226 insertions(+), 158 deletions(-)
---
diff --git a/include/Dialog_Base_Partition.h b/include/Dialog_Base_Partition.h
index 5397aea..031d6b2 100644
--- a/include/Dialog_Base_Partition.h
+++ b/include/Dialog_Base_Partition.h
@@ -64,7 +64,7 @@ protected:
        double MB_PER_PIXEL ;
        Sector TOTAL_MB ;
        Frame_Resizer_Base *frame_resizer_base;
-       Partition new_partition;
+       Partition * new_partition;
 
        Sector START; //the first sector of the first relevant partition ( this is either current or current 
-1 )  needed in Get_Resized_Partition()
        Sector total_length ; //total amount of sectors ( this can be up to 3 partitions...)
@@ -94,6 +94,9 @@ protected:
        FS fs ;
 
 private:
+       Dialog_Base_Partition( const Dialog_Base_Partition & src );              // Not implemented copy 
constructor
+       Dialog_Base_Partition & operator=( const Dialog_Base_Partition & rhs );  // Not implemented copy 
assignment operator
+
        void Check_Change( ) ;
        
        Gtk::VBox vbox_resize_move;
diff --git a/include/Dialog_Partition_Copy.h b/include/Dialog_Partition_Copy.h
index ca63983..7196f0f 100644
--- a/include/Dialog_Partition_Copy.h
+++ b/include/Dialog_Partition_Copy.h
@@ -29,10 +29,14 @@ class Dialog_Partition_Copy : public Dialog_Base_Partition
 public:
        Dialog_Partition_Copy( const FS & fs, const Partition & selected_partition,
                               const Partition & copied_partition );
+       ~Dialog_Partition_Copy();
 
        const Partition & Get_New_Partition( Byte_Value sector_size );
 
 private:
+       Dialog_Partition_Copy( const Dialog_Partition_Copy & src );              // Not implemented copy 
constructor
+       Dialog_Partition_Copy & operator=( const Dialog_Partition_Copy & rhs );  // Not implemented copy 
assignment operator
+
        void set_data( const Partition & selected_partition, const Partition & copied_partition );
 };
 
diff --git a/include/Dialog_Partition_New.h b/include/Dialog_Partition_New.h
index 669759d..6e1dbb1 100644
--- a/include/Dialog_Partition_New.h
+++ b/include/Dialog_Partition_New.h
@@ -35,9 +35,15 @@ public:
                             bool any_extended,
                             unsigned short new_count,
                             const std::vector<FS> & FILESYSTEMS );
+       ~Dialog_Partition_New();
+
        const Partition & Get_New_Partition( Byte_Value sector_size );
 
 private:
+       Dialog_Partition_New( const Dialog_Partition_New & src );              // Not implemented copy 
constructor
+       Dialog_Partition_New & operator=( const Dialog_Partition_New & rhs );  // Not implemented copy 
assignment operator
+
+
        void set_data( const Device & device,
                       const Partition & partition,
                       bool any_extended,
diff --git a/include/Dialog_Partition_Resize_Move.h b/include/Dialog_Partition_Resize_Move.h
index 98553b2..a2f163c 100644
--- a/include/Dialog_Partition_Resize_Move.h
+++ b/include/Dialog_Partition_Resize_Move.h
@@ -29,8 +29,12 @@ class Dialog_Partition_Resize_Move : public Dialog_Base_Partition
 public:
        Dialog_Partition_Resize_Move( const FS & fs, const Partition & selected_partition,
                                      const PartitionVector & partitions );
+       ~Dialog_Partition_Resize_Move();
 
 private:
+       Dialog_Partition_Resize_Move( const Dialog_Partition_Resize_Move & src );              // Not 
implemented copy constructor
+       Dialog_Partition_Resize_Move & operator=( const Dialog_Partition_Resize_Move & rhs );  // Not 
implemented assignment operator
+
        void set_data( const Partition & selected_partition, const PartitionVector & partitions );
        void Resize_Move_Normal( const PartitionVector & partitions );
        void Resize_Move_Extended( const PartitionVector & partitions );
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index 95b01ff..18907c7 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -139,93 +139,104 @@ void Dialog_Base_Partition::Set_Resizer( bool extended )
 
 const Partition & Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by derived Dialog_Partition_*() 
constructor calling set_data()
+
        prepare_new_partition( sector_size );
-       return new_partition;
+       return *new_partition;
 }
 
 void Dialog_Base_Partition::prepare_new_partition( Byte_Value sector_size )
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by derived Dialog_Partition_*() 
constructor calling set_data()
+
        //set sector size of new partition
-       new_partition.sector_size = sector_size;
-       Sector old_size = new_partition.get_sector_length();
+       new_partition->sector_size = sector_size;
+       Sector old_size = new_partition->get_sector_length();
 
        //FIXME:  Partition size is limited to just less than 1024 TeraBytes due
        //        to the maximum value of signed 4 byte integer.
        if ( ORIG_BEFORE != spinbutton_before .get_value_as_int() )
-               new_partition.sector_start = START + Sector(spinbutton_before.get_value_as_int()) * (MEBIBYTE 
/ sector_size);
+               new_partition->sector_start = START + Sector(spinbutton_before.get_value_as_int()) * 
(MEBIBYTE / sector_size);
 
        if ( ORIG_AFTER != spinbutton_after .get_value_as_int() )
-               new_partition.sector_end =
-                       new_partition.sector_start
+               new_partition->sector_end =
+                       new_partition->sector_start
                        + Sector(spinbutton_size .get_value_as_int()) * (MEBIBYTE / sector_size)
                        - 1 /* one sector short of exact mebibyte multiple */;
 
        //due to loss of precision during calcs from Sector -> MiB and back, it is possible
        //the new partition thinks it's bigger then it can be. Here we solve this.
-       if ( new_partition.sector_start < START )
-               new_partition.sector_start = START;
-       if ( new_partition.sector_end > ( START + total_length - 1 ) )
-               new_partition.sector_end = START + total_length - 1;
-       
+       if ( new_partition->sector_start < START )
+               new_partition->sector_start = START;
+       if ( new_partition->sector_end > ( START + total_length - 1 ) )
+               new_partition->sector_end = START + total_length - 1;
+
        //grow a bit into small freespace ( < 1MiB ) 
-       if ( (new_partition.sector_start - START) < (MEBIBYTE / sector_size) )
-               new_partition.sector_start = START;
-       if ( ( START + total_length -1 - new_partition.sector_end ) < (MEBIBYTE / sector_size) )
-               new_partition.sector_end = START + total_length - 1;
+       if ( (new_partition->sector_start - START) < (MEBIBYTE / sector_size) )
+               new_partition->sector_start = START;
+       if ( ( START + total_length -1 - new_partition->sector_end ) < (MEBIBYTE / sector_size) )
+               new_partition->sector_end = START + total_length - 1;
 
        //set alignment
        switch ( optionmenu_alignment .get_history() )
        {
-               case  0 :  new_partition.alignment = ALIGN_CYLINDER;  break;
-               case  1 :  new_partition.alignment = ALIGN_MEBIBYTE;
-                          {
-                              //if partition size is not an integer multiple of MiB
-                              //   or the start or end sectors are not MiB aligned,
-                              //   and space is available,
-                              //   then add 1 MiB to partition so requested size is kept
-                              //   after GParted_Core::snap_to_mebibyte method rounding
-                              Sector partition_size = new_partition.sector_end - new_partition.sector_start 
+ Sector(1);
-                              Sector sectors_in_mib = MEBIBYTE / new_partition.sector_size;
-                              if (   (   ( ( partition_size % sectors_in_mib ) > 0 )
-                                      || ( ( new_partition.sector_start % sectors_in_mib ) > 0 )
-                                      || ( ( ( new_partition.sector_end + Sector(1) ) % sectors_in_mib ) > 0 
)
-                                     )
-                                  && ( ( partition_size + sectors_in_mib ) < total_length )
-                                 )
-                                  new_partition.sector_end += sectors_in_mib;
-                          }
-                          break;
-               case  2 :  new_partition.alignment = ALIGN_STRICT;  break;
-
-               default :  new_partition.alignment = ALIGN_MEBIBYTE;  break;
+               case 0:
+                       new_partition->alignment = ALIGN_CYLINDER;
+                       break;
+               case 1:
+                       new_partition->alignment = ALIGN_MEBIBYTE;
+                       {
+                               // If partition size is not an integer multiple of MiB or
+                               // the start or end sectors are not MiB aligned, and space
+                               // is available, then add 1 MiB to partition so requested
+                               // size is kept after GParted_Core::snap_to_mebibyte
+                               // method rounding.
+                               Sector partition_size = new_partition->sector_end - 
new_partition->sector_start + 1;
+                               Sector sectors_in_mib = MEBIBYTE / new_partition->sector_size;
+                               if (    (    ( partition_size % sectors_in_mib                    > 0 )
+                                         || ( new_partition->sector_start % sectors_in_mib       > 0 )
+                                         || ( ( new_partition->sector_end + 1 ) % sectors_in_mib > 0 )
+                                       )
+                                    && ( partition_size + sectors_in_mib < total_length )
+                                  )
+                                       new_partition->sector_end += sectors_in_mib;
+                       }
+                       break;
+               case 2:
+                       new_partition->alignment = ALIGN_STRICT;
+                       break;
+
+               default:
+                       new_partition->alignment = ALIGN_MEBIBYTE;
+                       break;
        }
 
        //update partition usage
-       if ( new_partition.sectors_used != -1 && new_partition.sectors_unused != -1 )
+       if ( new_partition->sectors_used != -1 && new_partition->sectors_unused != -1 )
        {
-               Sector new_size = new_partition.get_sector_length();
+               Sector new_size = new_partition->get_sector_length();
                if ( old_size == new_size )
                {
                        //Pasting into new same sized partition or moving partition keeping the same size,
                        //  therefore only block copy operation will be performed maintaining file system 
size.
-                       new_partition.set_sector_usage(
-                                       new_partition.sectors_used + new_partition.sectors_unused,
-                                       new_partition.sectors_unused );
+                       new_partition->set_sector_usage(
+                                       new_partition->sectors_used + new_partition->sectors_unused,
+                                       new_partition->sectors_unused );
                }
                else
                {
                        //Pasting into new larger partition or (moving and) resizing partition larger or 
smaller,
                        //  therefore block copy followed by file system grow or shrink operations will be
                        //  performed making the file system fill the partition.
-                       new_partition.set_sector_usage( new_size, new_size - new_partition.sectors_used );
+                       new_partition->set_sector_usage( new_size, new_size - new_partition->sectors_used );
                }
        }
 
-       new_partition.free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / 
sector_size);
+       new_partition->free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / 
sector_size);
 
        //if the original before value has not changed, then set indicator to keep start sector unchanged
        if ( ORIG_BEFORE == spinbutton_before .get_value_as_int() )
-               new_partition.strict_start = TRUE;
+               new_partition->strict_start = TRUE;
 }
 
 void Dialog_Base_Partition::Set_Confirm_Button( CONFIRMBUTTON button_type ) 
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index b76327c..2d7b064 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -33,6 +33,12 @@ Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, const Partition & s
        set_data( selected_partition, copied_partition );
 }
 
+Dialog_Partition_Copy::~Dialog_Partition_Copy()
+{
+       delete new_partition;
+       new_partition = NULL;
+}
+
 void Dialog_Partition_Copy::set_data( const Partition & selected_partition, const Partition & 
copied_partition )
 {
        this ->set_title( String::ucompose( _("Paste %1"), copied_partition .get_path() ) ) ;
@@ -102,12 +108,12 @@ void Dialog_Partition_Copy::set_data( const Partition & selected_partition, cons
                       ) ;
 
        // Set member variable used in Dialog_Base_Partition::prepare_new_partition()
-       new_partition = copied_partition;
-       new_partition.device_path     = selected_partition.device_path;
-       new_partition.inside_extended = selected_partition.inside_extended;
-       new_partition.type            = selected_partition.inside_extended ? TYPE_LOGICAL : TYPE_PRIMARY;
+       new_partition = new Partition( copied_partition );
+       new_partition->device_path     = selected_partition.device_path;
+       new_partition->inside_extended = selected_partition.inside_extended;
+       new_partition->type            = selected_partition.inside_extended ? TYPE_LOGICAL : TYPE_PRIMARY;
        //Handle situation where src sector size is smaller than dst sector size and an additional partial 
dst sector is required.
-       new_partition.set_sector_usage(
+       new_partition->set_sector_usage(
                        (   ( ( copied_partition .sectors_used + copied_partition .sectors_unused ) * 
copied_partition .sector_size )
                          + ( selected_partition .sector_size - 1 )
                        ) / selected_partition .sector_size,
@@ -120,13 +126,15 @@ void Dialog_Partition_Copy::set_data( const Partition & selected_partition, cons
 
 const Partition & Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
+
        //first call baseclass to get the correct new partition
        Dialog_Base_Partition::prepare_new_partition( sector_size );
 
        //set proper name and status for partition
-       new_partition.status = STAT_COPY;
+       new_partition->status = STAT_COPY;
 
-       return new_partition;
+       return *new_partition;
 }
 
 } //GParted
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index b3a9ad4..f162ddd 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -39,6 +39,12 @@ Dialog_Partition_New::Dialog_Partition_New( const Device & device,
        set_data(device, selected_partition, any_extended, new_count, FILESYSTEMS );
 }
 
+Dialog_Partition_New::~Dialog_Partition_New()
+{
+       delete new_partition;
+       new_partition = NULL;
+}
+
 void Dialog_Partition_New::set_data( const Device & device,
                                      const Partition & selected_partition,
                                      bool any_extended,
@@ -46,7 +52,7 @@ void Dialog_Partition_New::set_data( const Device & device,
                                      const std::vector<FS> & FILESYSTEMS )
 {
        this ->new_count = new_count;
-       new_partition = selected_partition;
+       new_partition = new Partition( selected_partition );
 
        // Copy only supported file systems from GParted_Core FILESYSTEMS vector.  Add
        // FS_CLEARED, FS_UNFORMATTED and FS_EXTENDED at the end.  This decides the order
@@ -180,6 +186,8 @@ void Dialog_Partition_New::set_data( const Device & device,
 
 const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
+
        PartitionType part_type ;
        Sector new_start, new_end;
                
@@ -199,61 +207,68 @@ const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_siz
        
        /* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new 
         * partition thinks it's bigger then it can be. Here we try to solve this.*/
-       if ( new_start < new_partition.sector_start )
-               new_start = new_partition.sector_start;
-       if  ( new_end > new_partition.sector_end )
-               new_end = new_partition.sector_end;
+       if ( new_start < new_partition->sector_start )
+               new_start = new_partition->sector_start;
+       if  ( new_end > new_partition->sector_end )
+               new_end = new_partition->sector_end;
 
        // Grow new partition a bit if freespaces are < 1 MiB
-       if ( (new_start - new_partition.sector_start) < (MEBIBYTE / sector_size) )
-               new_start = new_partition.sector_start;
-       if ( (new_partition.sector_end - new_end) < (MEBIBYTE / sector_size) )
-               new_end = new_partition.sector_end;
+       if ( new_start - new_partition->sector_start < MEBIBYTE / sector_size )
+               new_start = new_partition->sector_start;
+       if ( new_partition->sector_end - new_end < MEBIBYTE / sector_size )
+               new_end = new_partition->sector_end;
 
        // Copy a final few values needed from the original unallocated partition before
        // resetting the Partition object and populating it as the new partition.
-       Glib::ustring device_path = new_partition.device_path;
-       bool whole_device = new_partition.whole_device;
-       bool inside_extended = new_partition.inside_extended;
-       new_partition.Reset();
-       new_partition.Set( device_path,
-                          String::ucompose( _("New Partition #%1"), new_count ),
-                          new_count, part_type, whole_device,
-                          FILESYSTEMS[optionmenu_filesystem.get_history()].filesystem,
-                          new_start, new_end,
-                          sector_size,
-                          inside_extended, false );
-       new_partition.status = STAT_NEW;
+       Glib::ustring device_path = new_partition->device_path;
+       bool whole_device = new_partition->whole_device;
+       bool inside_extended = new_partition->inside_extended;
+       new_partition->Reset();
+       new_partition->Set( device_path,
+                           String::ucompose( _("New Partition #%1"), new_count ),
+                           new_count, part_type, whole_device,
+                           FILESYSTEMS[optionmenu_filesystem.get_history()].filesystem,
+                           new_start, new_end,
+                           sector_size,
+                           inside_extended, false );
+       new_partition->status = STAT_NEW;
 
        // Retrieve partition name
-       new_partition.name = Utils::trim( partition_name_entry.get_text() );
+       new_partition->name = Utils::trim( partition_name_entry.get_text() );
 
        //Retrieve Label info
-       new_partition.set_filesystem_label( Utils::trim( filesystem_label_entry.get_text() ) );
+       new_partition->set_filesystem_label( Utils::trim( filesystem_label_entry.get_text() ) );
 
        //set alignment
        switch ( optionmenu_alignment .get_history() )
        {
-               case 0:   new_partition.alignment = ALIGN_CYLINDER;  break;
-               case 1:   new_partition.alignment = ALIGN_MEBIBYTE;
+               case 0:
+                       new_partition->alignment = ALIGN_CYLINDER;
+                       break;
+               case 1:
+                       new_partition->alignment = ALIGN_MEBIBYTE;
                        {
                                // If start sector not MiB aligned and free space available
                                // then add ~1 MiB to partition so requested size is kept
-                               Sector diff = (MEBIBYTE / new_partition.sector_size) -
-                                             (new_partition.sector_end + 1) % (MEBIBYTE / 
new_partition.sector_size);
+                               Sector diff = (MEBIBYTE / new_partition->sector_size) -
+                                             (new_partition->sector_end + 1) % (MEBIBYTE / 
new_partition->sector_size);
                                if (    diff
-                                    && ( new_partition.sector_start % (MEBIBYTE / new_partition.sector_size 
) ) > 0
-                                    && ( (new_partition.sector_end - START + 1 + diff) < total_length )
+                                    && new_partition->sector_start % (MEBIBYTE / new_partition->sector_size 
) > 0
+                                    && new_partition->sector_end - START + 1 + diff < total_length
                                   )
-                                       new_partition.sector_end += diff;
+                                       new_partition->sector_end += diff;
                        }
                        break;
-               case 2:   new_partition.alignment = ALIGN_STRICT;  break;
+               case 2:
+                       new_partition->alignment = ALIGN_STRICT;
+                       break;
 
-               default:  new_partition.alignment = ALIGN_MEBIBYTE;  break;
+               default:
+                       new_partition->alignment = ALIGN_MEBIBYTE;
+                       break;
        }
 
-       new_partition.free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / 
sector_size);
+       new_partition->free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / 
sector_size);
 
        // Create unallocated space within this new extended partition
        //
@@ -276,23 +291,25 @@ const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_siz
        // snap_to_alignment() needs including in it.  It will need abstracting into a set
        // of methods so that it can be used in each dialog which creates and modified
        // partition boundaries.
-       if ( new_partition.type == TYPE_EXTENDED )
+       if ( new_partition->type == TYPE_EXTENDED )
        {
                Partition * unallocated = new Partition();
-               unallocated->Set_Unallocated( new_partition.device_path,
-                                             new_partition.whole_device,
-                                             new_partition.sector_start,
-                                             new_partition.sector_end,
+               unallocated->Set_Unallocated( new_partition->device_path,
+                                             new_partition->whole_device,
+                                             new_partition->sector_start,
+                                             new_partition->sector_end,
                                              sector_size,
                                              true );
-               new_partition.logicals.push_back_adopt( unallocated );
+               new_partition->logicals.push_back_adopt( unallocated );
        }
 
-       return new_partition;
+       return *new_partition;
 }
 
 void Dialog_Partition_New::optionmenu_changed( bool type )
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
+
        //optionmenu_type
        if ( type )
        {
@@ -321,8 +338,8 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
                if ( fs .MIN < MEBIBYTE )
                        fs .MIN = MEBIBYTE ;
 
-               if ( new_partition.get_byte_length() < fs.MIN )
-                       fs .MIN = new_partition.get_byte_length();
+               if ( new_partition->get_byte_length() < fs.MIN )
+                       fs.MIN = new_partition->get_byte_length();
 
                if ( ! fs .MAX || ( fs .MAX > ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) ) )
                        fs .MAX = ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) ;
@@ -369,6 +386,8 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
 
 void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted ) 
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
+
        bool set_first=false;
        //fill the file system menu with the file systems (except for extended) 
        for ( unsigned int t = 0 ; t < FILESYSTEMS .size( ) ; t++ ) 
@@ -380,7 +399,7 @@ void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted )
                        Gtk::Menu_Helpers::MenuElem( Utils::get_filesystem_string( FILESYSTEMS[ t ] 
.filesystem ) ) ) ;
                menu_filesystem .items() .back() .set_sensitive(
                        ! only_unformatted && FILESYSTEMS[ t ] .create &&
-                       new_partition.get_byte_length() >= FILESYSTEMS[t].MIN );
+                       new_partition->get_byte_length() >= FILESYSTEMS[t].MIN );
                //use ext4/3/2 as first/second/third choice default file system
                //(Depends on ordering in FILESYSTEMS for preference)
                if ( ( FILESYSTEMS[ t ] .filesystem == FS_EXT2 ||
diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc
index f907215..1ab81f2 100644
--- a/src/Dialog_Partition_Resize_Move.cc
+++ b/src/Dialog_Partition_Resize_Move.cc
@@ -30,12 +30,18 @@ Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs, const
        set_data( selected_partition, partitions );
 }
 
+Dialog_Partition_Resize_Move::~Dialog_Partition_Resize_Move()
+{
+       delete new_partition;
+       new_partition = NULL;
+}
+
 void Dialog_Partition_Resize_Move::set_data( const Partition & selected_partition,
                                              const PartitionVector & partitions )
 {
        GRIP = true ; //prevents on spinbutton_changed from getting activated prematurely
 
-       new_partition = selected_partition;
+       new_partition = new Partition( selected_partition );
 
        if ( selected_partition .type == GParted::TYPE_EXTENDED )
        {
@@ -64,29 +70,31 @@ void Dialog_Partition_Resize_Move::set_data( const Partition & selected_partitio
 
 void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & partitions )
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
+
        //little bit of paranoia ;)
-       if ( ! new_partition.sector_usage_known() &&
-            new_partition.status != STAT_NEW &&
-            new_partition.filesystem != FS_LINUX_SWAP )
+       if ( ! new_partition->sector_usage_known()      &&
+            new_partition->status     != STAT_NEW      &&
+            new_partition->filesystem != FS_LINUX_SWAP    )
                fs .shrink = GParted::FS::NONE ;
        
        //Disable resizing as it's currently disallowed for the file system in this partition.
        //  (Updates this class's copy of file system support information).
-       if ( GParted_Core::filesystem_resize_disallowed( new_partition ) )
+       if ( GParted_Core::filesystem_resize_disallowed( *new_partition ) )
        {
                fs .shrink = FS::NONE ;
                fs .grow   = FS::NONE ;
        }
 
        // See if we can allow the start of the file system to move
-       if ( fs.move && ! new_partition.busy && ! new_partition.whole_device )
+       if ( fs.move && ! new_partition->busy && ! new_partition->whole_device )
        {
-               set_title( String::ucompose( _("Resize/Move %1"), new_partition.get_path() ) );
+               set_title( String::ucompose( _("Resize/Move %1"), new_partition->get_path() ) );
                frame_resizer_base ->set_fixed_start( false ) ;
        }
        else
        {
-               set_title( String::ucompose( _("Resize %1"), new_partition.get_path() ) );
+               set_title( String::ucompose( _("Resize %1"), new_partition->get_path() ) );
                this ->fixed_start = true;
                frame_resizer_base ->set_fixed_start( true ) ;
                spinbutton_before .set_sensitive( false ) ;
@@ -96,7 +104,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
        //first find index of partition
        unsigned int t;
        for ( t = 0 ; t < partitions .size() ; t++ )
-               if ( partitions[t] == new_partition )
+               if ( partitions[t] == *new_partition )
                        break;
 
        Sector previous, next ;
@@ -108,8 +116,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
                START = partitions[t -1] .sector_start ;
        } 
        else
-               START = new_partition.sector_start;
-       
+               START = new_partition->sector_start;
+
        if ( t +1 < partitions .size() && partitions[t +1] .type == GParted::TYPE_UNALLOCATED )
        {
                next = partitions[t +1] .get_sector_length() ;
@@ -117,9 +125,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
                //If this is a logical partition and there is extra free space
                //  then check if we need to reserve 1 MiB of space after for
                //  the next logical partition Extended Boot Record.
-               if (   new_partition.type == TYPE_LOGICAL
-                   && next >= (MEBIBYTE / new_partition.sector_size)
-                  )
+               if ( new_partition->type == TYPE_LOGICAL                          &&
+                    next                >= MEBIBYTE / new_partition->sector_size    )
                {
                        //Find maximum sector_end (allocated or unallocated) within list of
                        //  partitions inside the extended partition
@@ -131,8 +138,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
                        }
 
                        //If not within 1 MiB of the end of the extended partition, then reserve 1 MiB
-                       if ( ( max_sector_end - partitions[t+1].sector_end ) > ( MEBIBYTE / 
new_partition.sector_size ) )
-                               next -= MEBIBYTE / new_partition.sector_size;
+                       if ( max_sector_end - partitions[t+1].sector_end > MEBIBYTE / 
new_partition->sector_size )
+                               next -= MEBIBYTE / new_partition->sector_size;
                }
        }
 
@@ -143,13 +150,13 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
                MIN_SPACE_BEFORE_MB = 0 ;
        else
        {
-               if ( START <= (MEBIBYTE / new_partition.sector_size) )
+               if ( START <= MEBIBYTE / new_partition->sector_size )
                        MIN_SPACE_BEFORE_MB = 1 ;
                else
-                       MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( new_partition 
);
+                       MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( 
*new_partition );
        }
-       total_length = previous + new_partition.get_sector_length() + next;
-       TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, new_partition.sector_size, UNIT_MIB ) );
+       total_length = previous + new_partition->get_sector_length() + next;
+       TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, new_partition->sector_size, UNIT_MIB ) 
);
        
        MB_PER_PIXEL = TOTAL_MB / 500.00 ;
                
@@ -157,31 +164,30 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
        frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ;
        frame_resizer_base ->set_x_start( Utils::round( previous / ( total_length / 500.00 ) ) ) ;
        frame_resizer_base ->set_x_end( 
-               Utils::round( new_partition.get_sector_length() / ( total_length / 500.00 ) ) + 
frame_resizer_base->get_x_start() );
-       Sector min_resize = new_partition.estimated_min_size();
+                       Utils::round( new_partition->get_sector_length() / ( total_length / 500.00 ) ) + 
frame_resizer_base->get_x_start() );
+       Sector min_resize = new_partition->estimated_min_size();
        frame_resizer_base ->set_used( Utils::round( min_resize / ( total_length / 500.00 ) ) ) ;
 
        //set MIN
-       if (   ( fs.shrink && ! new_partition.busy )
-           || ( fs.online_shrink && new_partition.busy )
-          )
+       if ( ( fs.shrink        && ! new_partition->busy ) ||
+            ( fs.online_shrink && new_partition->busy   )    )
        {
                //since some file systems have lower limits we need to check for this
-               if ( min_resize > (fs.MIN / new_partition.sector_size) )
-                       fs.MIN = min_resize * new_partition.sector_size;
+               if ( min_resize > fs.MIN / new_partition->sector_size )
+                       fs.MIN = min_resize * new_partition->sector_size;
 
                //ensure that minimum size is at least one mebibyte
                if ( ! fs .MIN || fs .MIN < MEBIBYTE )
                        fs .MIN = MEBIBYTE ;
        }
        else
-               fs.MIN = new_partition.get_byte_length();
+               fs.MIN = new_partition->get_byte_length();
 
        //set MAX
        if ( fs .grow )
                fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ;
        else
-               fs.MAX = new_partition.get_byte_length();
+               fs.MAX = new_partition->get_byte_length();
 
        //set values of spinbutton_before
        if ( ! fixed_start )
@@ -190,7 +196,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
                                            , TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) )
                                            ) ;
                spinbutton_before .set_value(
-                       Utils::round( Utils::sector_to_unit( previous, new_partition.sector_size, UNIT_MIB ) 
) );
+                       Utils::round( Utils::sector_to_unit( previous, new_partition->sector_size, UNIT_MIB ) 
) );
        }
 
        //set values of spinbutton_size 
@@ -198,15 +204,15 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
                                  , ceil( fs .MAX / double(MEBIBYTE) )
                                  ) ;
        spinbutton_size .set_value( 
-               Utils::round( Utils::sector_to_unit( new_partition.get_sector_length(), 
new_partition.sector_size, UNIT_MIB ) ) );
-       
+               Utils::round( Utils::sector_to_unit( new_partition->get_sector_length(), 
new_partition->sector_size, UNIT_MIB ) ) );
+
        //set values of spinbutton_after
        Sector after_min = ( ! fs .grow && ! fs .move ) ? next : 0 ;
        spinbutton_after .set_range( 
-               Utils::round( Utils::sector_to_unit( after_min, new_partition.sector_size, UNIT_MIB ) ),
+               Utils::round( Utils::sector_to_unit( after_min, new_partition->sector_size, UNIT_MIB ) ),
                TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ;
        spinbutton_after .set_value( 
-               Utils::round( Utils::sector_to_unit( next, new_partition.sector_size, UNIT_MIB ) ) );
+               Utils::round( Utils::sector_to_unit( next, new_partition->sector_size, UNIT_MIB ) ) );
 
        frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
                                              Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ;
@@ -219,6 +225,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
 
 void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector & partitions )
 {
+       g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
+
        //calculate total size in MiB's of previous, current and next partition
        //first find index of partition
        unsigned int t = 0;
@@ -233,8 +241,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
                START = partitions[t -1] .sector_start ;
        } 
        else
-               START = new_partition.sector_start;
-       
+               START = new_partition->sector_start;
+
        //calculate length of next
        if ( t +1 < partitions .size() && partitions[ t +1 ] .type == GParted::TYPE_UNALLOCATED )
                next = partitions[ t +1 ] .get_sector_length() ;
@@ -246,32 +254,30 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
        if ( previous <= 0 )
                MIN_SPACE_BEFORE_MB = 0 ;
        else
-               MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( new_partition );
-       total_length = previous + new_partition.get_sector_length() + next;
-       TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, new_partition.sector_size, UNIT_MIB ) );
+               MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( *new_partition );
+       total_length = previous + new_partition->get_sector_length() + next;
+       TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, new_partition->sector_size, UNIT_MIB ) 
);
        MB_PER_PIXEL = TOTAL_MB / 500.00 ;
        
        //calculate proportional length of partition ( in pixels )
        frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ;
        frame_resizer_base ->set_x_start( Utils::round( previous / ( total_length / 500.00 ) ) ) ;
-       frame_resizer_base ->set_x_end( Utils::round( new_partition.get_sector_length() / ( total_length / 
500.00 ) ) + frame_resizer_base ->get_x_start() );
+       frame_resizer_base ->set_x_end( Utils::round( new_partition->get_sector_length() / ( total_length / 
500.00 ) ) + frame_resizer_base->get_x_start() );
        
        //used is a bit different here... we consider start of first logical to end last logical as used space
        Sector first =0, last = 0, used =0 ;
-       if ( ! (   new_partition.logicals.size() == 1
-               && new_partition.logicals.back().type == TYPE_UNALLOCATED
-              )
-          )
+       if ( ! ( new_partition->logicals.size()      == 1                &&
+                new_partition->logicals.back().type == TYPE_UNALLOCATED    ) )
        {
                //logical partitions other than unallocated exist
-               first = new_partition.sector_end;
-               last = new_partition.sector_start;
+               first = new_partition->sector_end;
+               last = new_partition->sector_start;
                for ( unsigned int i = 0 ; i < partitions[ t ] .logicals .size() ; i++ )
                {
                        if ( partitions[ t ] .logicals[ i ] .type == GParted::TYPE_LOGICAL )
                        {
                                if ( partitions[ t ] .logicals[ i ] .sector_start < first )
-                                       first = partitions[ t ] .logicals[ i ] .sector_start - (MEBIBYTE / 
new_partition.sector_size);
+                                       first = partitions[t].logicals[i].sector_start - (MEBIBYTE / 
new_partition->sector_size);
                                if ( first < 0 )
                                        first = 0 ;
                                if ( partitions[ t ] .logicals[ i ] .sector_end > last )
@@ -287,7 +293,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
                fs .MIN = MEBIBYTE ;
        }
        else 
-               fs.MIN = used * new_partition.sector_size;
+               fs.MIN = used * new_partition->sector_size;
 
        //set MAX
        fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ;
@@ -300,29 +306,36 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
        if ( first == 0 ) //no logicals
                spinbutton_before .set_range( MIN_SPACE_BEFORE_MB, TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs 
.MIN / double(MEBIBYTE) ) ) ;
        else
-               spinbutton_before .set_range( MIN_SPACE_BEFORE_MB, Utils::round( Utils::sector_to_unit( first 
- START, new_partition.sector_size, UNIT_MIB ) ) );
-       
-       spinbutton_before .set_value( Utils::round( Utils::sector_to_unit( previous, 
new_partition.sector_size, UNIT_MIB ) ) );
-       
+               spinbutton_before.set_range( MIN_SPACE_BEFORE_MB,
+                                            Utils::round( Utils::sector_to_unit( first - START,
+                                                                                 new_partition->sector_size,
+                                                                                 UNIT_MIB ) ) );
+
+       spinbutton_before.set_value( Utils::round( Utils::sector_to_unit( previous,
+                                                                         new_partition->sector_size, 
UNIT_MIB ) ) );
+
        //set values of spinbutton_size
        spinbutton_size .set_range( ceil( fs .MIN / double(MEBIBYTE) ), TOTAL_MB - MIN_SPACE_BEFORE_MB ) ;
-       
-       spinbutton_size .set_value(
-               Utils::round( Utils::sector_to_unit( new_partition.get_sector_length(), 
new_partition.sector_size, UNIT_MIB ) ) );
-       
+
+       spinbutton_size.set_value( Utils::round( Utils::sector_to_unit( new_partition->get_sector_length(),
+                                                                       new_partition->sector_size, UNIT_MIB 
) ) );
+
        //set values of spinbutton_after
        if ( first == 0 ) //no logicals
                spinbutton_after .set_range( 
                        0, TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) ) - MIN_SPACE_BEFORE_MB ) ;
        else
-               spinbutton_after .set_range( 
-                       0, Utils::round( Utils::sector_to_unit( total_length + START - first - used, 
new_partition.sector_size, UNIT_MIB ) ) );
-       
-       spinbutton_after .set_value( Utils::round( Utils::sector_to_unit( next, new_partition.sector_size, 
UNIT_MIB ) ) );
-       
+               spinbutton_after.set_range( 0, Utils::round( Utils::sector_to_unit( total_length + START - 
first - used,
+                                                                                   
new_partition->sector_size,
+                                                                                   UNIT_MIB ) ) );
+
+       spinbutton_after.set_value( Utils::round( Utils::sector_to_unit( next,
+                                                                        new_partition->sector_size, UNIT_MIB 
) ) );
+
        //set contents of label_minmax
-       Set_MinMax_Text( ceil( fs .MIN / double(MEBIBYTE) )
-                      , Utils::round( Utils::sector_to_unit( total_length - (MIN_SPACE_BEFORE_MB * (MEBIBYTE 
/ new_partition.sector_size)), new_partition.sector_size, UNIT_MIB ) ) );
+       Set_MinMax_Text( ceil( fs.MIN / double(MEBIBYTE) ),
+                        Utils::round( Utils::sector_to_unit( total_length - MIN_SPACE_BEFORE_MB * (MEBIBYTE 
/ new_partition->sector_size),
+                                                             new_partition->sector_size, UNIT_MIB ) ) );
 }
 
 } //GParted



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