From cbfb7e51f50b36a7b190e8ade94ef0114f1fb3a8 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 27 Sep 2015 09:30:13 +0100 Subject: [PATCH] Replace Operation class members index and index_extended with local variables (#755214) These member variables store no Operation class information and were being used as local variables. Replace with local variables. Also indent a code block within an if clause so that the compiler can confirm that the new local variable isn't used uninitialised. Prevents this compiler warning: OperationResizeMove.cc: In member function 'void GParted::OperationResizeMove::apply_normal_to_visual(std::vector >&)': OperationResizeMove.cc:125: warning: 'index' may be used uninitialized in this function Bug 755214 - Refactor operation merging --- include/Operation.h | 3 --- src/Operation.cc | 6 ++++++ src/OperationDelete.cc | 3 +++ src/OperationResizeMove.cc | 29 +++++++++++++++++------------ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/Operation.h b/include/Operation.h index 7d068934..83ea8c89 100644 --- a/include/Operation.h +++ b/include/Operation.h @@ -65,9 +65,6 @@ protected: void insert_unallocated( std::vector & partitions, Sector start, Sector end, Byte_Value sector_size, bool inside_extended ); void substitute_new( std::vector & partitions ); void insert_new( std::vector & partitions ); - - int index ; - int index_extended ; }; } //GParted diff --git a/src/Operation.cc b/src/Operation.cc index 1f963a8a..5b16ca61 100644 --- a/src/Operation.cc +++ b/src/Operation.cc @@ -110,6 +110,9 @@ void Operation::insert_unallocated( std::vector & partitions, Sector // it with this operation's new partition. void Operation::substitute_new( std::vector & partitions ) { + int index_extended; + int index; + if ( partition_original.inside_extended ) { index_extended = find_index_extended( partitions ); @@ -140,6 +143,9 @@ void Operation::insert_new( std::vector & partitions ) // on disk. Therefore they match the original partition when visually re-applying // their operations to the disk graphic. Hence their use of, // find_index_original(). + int index_extended; + int index; + if ( partition_new.inside_extended ) { index_extended = find_index_extended( partitions ); diff --git a/src/OperationDelete.cc b/src/OperationDelete.cc index a04c5f02..8b34ec39 100644 --- a/src/OperationDelete.cc +++ b/src/OperationDelete.cc @@ -30,6 +30,9 @@ OperationDelete::OperationDelete( const Device & device, const Partition & parti void OperationDelete::apply_to_visual( std::vector & partitions ) { + int index_extended; + int index; + if ( partition_original .inside_extended ) { index_extended = find_index_extended( partitions ) ; diff --git a/src/OperationResizeMove.cc b/src/OperationResizeMove.cc index 16982f67..de511489 100644 --- a/src/OperationResizeMove.cc +++ b/src/OperationResizeMove.cc @@ -33,8 +33,6 @@ OperationResizeMove::OperationResizeMove( const Device & device, void OperationResizeMove::apply_to_visual( std::vector & partitions ) { - index = index_extended = -1 ; - if ( partition_original .type == GParted::TYPE_EXTENDED ) apply_extended_to_visual( partitions ) ; else @@ -123,23 +121,28 @@ void OperationResizeMove::create_description() void OperationResizeMove::apply_normal_to_visual( std::vector & partitions ) { + int index_extended; + int index; + if ( partition_original .inside_extended ) { index_extended = find_index_extended( partitions ) ; if ( index_extended >= 0 ) - index = find_index_original( partitions[ index_extended ] .logicals ) ; - - if ( index >= 0 ) { - partitions[ index_extended ] .logicals[ index ] = partition_new ; - remove_adjacent_unallocated( partitions[ index_extended ] .logicals, index ) ; + index = find_index_original( partitions[ index_extended ] .logicals ) ; - insert_unallocated( partitions[ index_extended ] .logicals, - partitions[ index_extended ] .sector_start, - partitions[ index_extended ] .sector_end, - device .sector_size, - true ) ; + if ( index >= 0 ) + { + partitions[index_extended].logicals[index] = partition_new; + remove_adjacent_unallocated( partitions[index_extended].logicals, index ); + + insert_unallocated( partitions[index_extended].logicals, + partitions[index_extended].sector_start, + partitions[index_extended].sector_end, + device.sector_size, + true ); + } } } else @@ -158,6 +161,8 @@ void OperationResizeMove::apply_normal_to_visual( std::vector & parti void OperationResizeMove::apply_extended_to_visual( std::vector & partitions ) { + int index_extended; + //stuff OUTSIDE extended partition index_extended = find_index_extended( partitions ) ;