Rename function to merge_two_operations() and update validation (#755214)
Rename Win_GParted::Merge_Operations() to merge_two_operations(). To reflect what it does and in preparation for further refactoring of the code. Be more strict on the validation of the first and second indexes. The first operation must also be before the second operation in the operation[] vector. (It is actually a programming bug if first and second fail validation. However so far g_assert() is only being used to validate pointers, which if wrong would likely cause the program to eventually crash when dereferenced later. In this case a bug would merely cause the incorrectly specified pair of operations to not be merged). Move validate_display_partition_ptr() declaration in the header file to be in the same ordering as it's definition in the source file. Bug 755214 - Refactor operation merging
This commit is contained in:
parent
7f4ffd28d5
commit
d93d8abcc4
|
@ -60,9 +60,9 @@ private:
|
||||||
void Fill_Label_Device_Info( bool clear = false );
|
void Fill_Label_Device_Info( bool clear = false );
|
||||||
|
|
||||||
void Add_Operation( Operation * operation, int index = -1 ) ;
|
void Add_Operation( Operation * operation, int index = -1 ) ;
|
||||||
bool valid_display_partition_ptr( const Partition * partition_ptr );
|
bool merge_two_operations( unsigned int first, unsigned int second );
|
||||||
bool Merge_Operations( unsigned int first, unsigned int second );
|
|
||||||
void Refresh_Visual();
|
void Refresh_Visual();
|
||||||
|
bool valid_display_partition_ptr( const Partition * partition_ptr );
|
||||||
bool Quit_Check_Operations();
|
bool Quit_Check_Operations();
|
||||||
void set_valid_operations() ;
|
void set_valid_operations() ;
|
||||||
void show_operationslist() ;
|
void show_operationslist() ;
|
||||||
|
|
|
@ -741,9 +741,12 @@ void Win_GParted::Add_Operation( Operation * operation, int index )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to merge the second operation into the first in the operations[] vector.
|
// Try to merge the second operation into the first in the operations[] vector.
|
||||||
bool Win_GParted::Merge_Operations( unsigned int first, unsigned int second )
|
bool Win_GParted::merge_two_operations( unsigned int first, unsigned int second )
|
||||||
{
|
{
|
||||||
if( first >= operations .size() || second >= operations .size() )
|
unsigned int num_ops = operations.size();
|
||||||
|
if ( first >= num_ops-1 )
|
||||||
|
return false;
|
||||||
|
if ( first >= second || second >= num_ops )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( operations[first]->merge_operations( *operations[second] ) )
|
if ( operations[first]->merge_operations( *operations[second] ) )
|
||||||
|
@ -827,7 +830,7 @@ void Win_GParted::Refresh_Visual()
|
||||||
//
|
//
|
||||||
// Win_GParted::activate_label_filesystem()
|
// Win_GParted::activate_label_filesystem()
|
||||||
// Win_GParted::Add_Operation( operation )
|
// Win_GParted::Add_Operation( operation )
|
||||||
// Win_GParted::Merge_Operations( ... )
|
// Win_GParted::merge_two_operations( ... )
|
||||||
// Win_GParted::show_operationslist()
|
// Win_GParted::show_operationslist()
|
||||||
// Win_GParted::Refresh_Visual()
|
// Win_GParted::Refresh_Visual()
|
||||||
//
|
//
|
||||||
|
@ -1745,7 +1748,7 @@ void Win_GParted::activate_resize()
|
||||||
// operation only.
|
// operation only.
|
||||||
if ( operations .size() >= 2 )
|
if ( operations .size() >= 2 )
|
||||||
{
|
{
|
||||||
Merge_Operations(operations .size() - 2, operations .size() - 1);
|
merge_two_operations( operations.size() - 2, operations.size() - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2013,7 +2016,7 @@ void Win_GParted::activate_delete()
|
||||||
// merged when adjacent).
|
// merged when adjacent).
|
||||||
for ( int t = 0 ; t < static_cast<int>( operations .size() - 1 ) ; t++ )
|
for ( int t = 0 ; t < static_cast<int>( operations .size() - 1 ) ; t++ )
|
||||||
{
|
{
|
||||||
Merge_Operations( t, t+1 );
|
merge_two_operations( t, t+1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh_Visual();
|
Refresh_Visual();
|
||||||
|
@ -2150,7 +2153,7 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
|
||||||
// Try to merge this format operation with the previous operation only.
|
// Try to merge this format operation with the previous operation only.
|
||||||
if ( operations .size() >= 2 )
|
if ( operations .size() >= 2 )
|
||||||
{
|
{
|
||||||
Merge_Operations( operations .size() - 2, operations .size() - 1 );
|
merge_two_operations( operations.size() - 2, operations.size() - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2604,7 +2607,7 @@ void Win_GParted::activate_check()
|
||||||
{
|
{
|
||||||
if ( operations[ t ] ->type == OPERATION_CHECK )
|
if ( operations[ t ] ->type == OPERATION_CHECK )
|
||||||
{
|
{
|
||||||
if( Merge_Operations( t, operations .size() -1 ) )
|
if ( merge_two_operations( t, operations.size() - 1 ) )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2641,7 +2644,7 @@ void Win_GParted::activate_label_filesystem()
|
||||||
{
|
{
|
||||||
if ( operations[t]->type == OPERATION_LABEL_FILESYSTEM )
|
if ( operations[t]->type == OPERATION_LABEL_FILESYSTEM )
|
||||||
{
|
{
|
||||||
if( Merge_Operations( t, operations .size() -1 ) )
|
if ( merge_two_operations( t, operations.size() - 1 ) )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2680,7 +2683,7 @@ void Win_GParted::activate_name_partition()
|
||||||
{
|
{
|
||||||
if ( operations[t]->type == OPERATION_NAME_PARTITION )
|
if ( operations[t]->type == OPERATION_NAME_PARTITION )
|
||||||
{
|
{
|
||||||
if( Merge_Operations( t, operations.size() - 1 ) )
|
if( merge_two_operations( t, operations.size() - 1 ) )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2737,7 +2740,7 @@ void Win_GParted::activate_change_uuid()
|
||||||
{
|
{
|
||||||
if ( operations[ t ] ->type == OPERATION_CHANGE_UUID )
|
if ( operations[ t ] ->type == OPERATION_CHANGE_UUID )
|
||||||
{
|
{
|
||||||
if( Merge_Operations( t, operations .size() -1 ) )
|
if( merge_two_operations( t, operations .size() - 1 ) )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue