Stop assigning a zero length string when constructing them

Most of the code doesn't assign a zero length string when constructing a
string object.  However there were a few places where it did.  This is
unnecessary because Glib::ustring [1] and std::string [2] objects are
constructed as the the empty string by default.

[1] Glib::ustring::ustring()
    https://developer-old.gnome.org/glibmm/stable/classGlib_1_1ustring.html#a71802782f4c2c408ef7ac69c6564b370
        "Glib::ustring::ustring()
        Default constructor, which creates an empty string.
        "
[2] std::string::string
    https://cplusplus.com/reference/string/string/string/
        "(1) empty string constructor (default constructor)
        Constructs an empty string, with a length of zero characters.
        "
This commit is contained in:
Mike Fleetwood 2024-04-06 08:05:04 +01:00
parent cc65eef59a
commit 61ac1a416f
12 changed files with 18 additions and 20 deletions

View file

@ -210,12 +210,11 @@ void DMRaid::get_devices( std::vector<Glib::ustring> & device_list )
Glib::ustring DMRaid::get_dmraid_name( const Glib::ustring & dev_path )
{
//Retrieve name of dmraid device
Glib::ustring dmraid_name = "" ;
Glib::ustring regexp = "" ;
Glib::ustring dmraid_name;
for ( unsigned int k=0; k < dmraid_devices .size(); k++ )
{
regexp = ".*(" + dmraid_devices[k] + ").*" ;
Glib::ustring regexp = ".*(" + dmraid_devices[k] + ").*";
if ( Utils::regexp_label( dev_path, regexp ) == dmraid_devices[k] )
dmraid_name = dmraid_devices[k] ;
}
@ -256,7 +255,7 @@ void DMRaid::get_dmraid_dir_entries( const Glib::ustring & dev_path, std::vector
Glib::ustring dmraid_name = get_dmraid_name( dev_path ) ;
//Loop through the entries in the directory
Glib::ustring filename = "" ;
Glib::ustring filename;
Glib::Dir dir( DEV_MAPPER_PATH );
while ( ( filename = dir .read_name() ) != "" )
{
@ -277,9 +276,9 @@ int DMRaid::get_partition_number( const Glib::ustring & partition_name )
Glib::ustring DMRaid::get_udev_dm_name( const Glib::ustring & dev_path )
{
//Retrieve DM_NAME of device using udev information
Glib::ustring output = "" ;
Glib::ustring error = "" ;
Glib::ustring dm_name = "" ;
Glib::ustring output;
Glib::ustring error;
Glib::ustring dm_name;
if (udevadm_found)
Utils::execute_command( "udevadm info --query=all --name=" + Glib::shell_quote( dev_path ),

View file

@ -228,7 +228,7 @@ void Dialog_Partition_Info::Display_Info()
Sector ptn_sectors = partition .get_sector_length() ;
Glib::ustring vgname = "" ; //Also used in partition status message
Glib::ustring vgname;
if (filesystem_ptn.fstype == FS_LVM2_PV)
vgname = LVM2_PV_Info::get_vg_name( filesystem_ptn.get_path() );

View file

@ -1235,7 +1235,6 @@ FSType GParted_Core::detect_filesystem(const PedDevice *lp_device, const PedPart
{
g_assert(lp_device != nullptr); // Bug: Not initialised by call to ped_device_get() or ped_device_get_next()
Glib::ustring fsname = "";
Glib::ustring path;
DMRaid dmraid;
@ -1257,7 +1256,7 @@ FSType GParted_Core::detect_filesystem(const PedDevice *lp_device, const PedPart
// (Q2) FS_Info (blkid) file system detection
// Blkid detects more signatures and generally has less limitations so use before
// libparted detection, but it doesn't report anything for extended partitions.
fsname = FS_Info::get_fs_type( path );
Glib::ustring fsname = FS_Info::get_fs_type(path);
// (Q3) Libparted file system detection
// Only used when blkid didn't report anything and only on partitions, not whole

View file

@ -3322,7 +3322,7 @@ void Win_GParted::activate_change_uuid()
Gtk::MESSAGE_WARNING,
Gtk::BUTTONS_OK,
true );
Glib::ustring tmp_msg = "" ;
Glib::ustring tmp_msg;
for ( i = 1 ; filesystem_object->get_custom_text( CTEXT_CHANGE_UUID_WARNING, i ) != "" ; i++ )
{
if ( i > 1 )
@ -3564,7 +3564,7 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
true, false, false, Gtk::ALIGN_START);
grid->attach(*label_members, 0, 1, 1, 1);
Glib::ustring members_str = "" ;
Glib::ustring members_str;
if ( ! members .empty() )
{
for ( unsigned int i = 0 ; i < members .size() ; i ++ )

View file

@ -128,7 +128,7 @@ bool f2fs::create( const Partition & new_partition, OperationDetail & operationd
bool f2fs::resize(const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition)
{
Glib::ustring size = "";
Glib::ustring size;
if (! fill_partition)
// resize.f2fs works in sector size units of whatever device the file
// system is currently stored on.

View file

@ -209,7 +209,7 @@ void fat16::read_label(Partition& partition)
bool fat16::write_label( const Partition & partition, OperationDetail & operationdetail )
{
Glib::ustring cmd = "" ;
Glib::ustring cmd;
if ( partition.get_filesystem_label().empty() )
cmd = "mlabel -c -i " + Glib::shell_quote(partition.get_path()) + " ::";
else

View file

@ -57,7 +57,7 @@ FS hfs::get_filesystem_support()
bool hfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
Glib::ustring cmd = "";
Glib::ustring cmd;
if( new_partition.get_filesystem_label().empty() )
cmd = "hformat " + Glib::shell_quote( new_partition.get_path() );
else

View file

@ -55,7 +55,7 @@ FS hfsplus::get_filesystem_support()
bool hfsplus::create( const Partition & new_partition, OperationDetail & operationdetail )
{
Glib::ustring cmd = "";
Glib::ustring cmd;
if( new_partition.get_filesystem_label().empty() )
cmd = "mkfs.hfsplus " + Glib::shell_quote( new_partition.get_path() );
else

View file

@ -151,7 +151,7 @@ bool luks::resize( const Partition & partition_new, OperationDetail & operationd
}
}
Glib::ustring size = "";
Glib::ustring size;
if ( ! fill_partition )
// Cryptsetup resize takes the size of the encryption mapping, not the
// size of the underlying block device. Both device-mapper and cryptsetup

View file

@ -105,7 +105,7 @@ bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operati
bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
Glib::ustring size = "" ;
Glib::ustring size;
if ( ! fill_partition )
size = " --yes --setphysicalvolumesize " +
Utils::num_to_str(partition_new.get_byte_length() / KIBIBYTE) + "K ";

View file

@ -190,7 +190,7 @@ bool ntfs::create( const Partition & new_partition, OperationDetail & operationd
bool ntfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
bool success;
Glib::ustring size = "" ;
Glib::ustring size;
if ( ! fill_partition )
size = " -s " + Utils::num_to_str(partition_new.get_byte_length());
Glib::ustring cmd = "ntfsresize --force --force" + size ;

View file

@ -176,7 +176,7 @@ bool reiserfs::create( const Partition & new_partition, OperationDetail & operat
bool reiserfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
Glib::ustring size = "" ;
Glib::ustring size;
if ( ! fill_partition )
size = " -s " + Utils::num_to_str(partition_new.get_byte_length());
const Glib::ustring resize_cmd = "echo y | resize_reiserfs" + size +