From 9910b23152e5f2bc70488de8e24044be668d34c1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 23 Oct 2020 22:34:53 +0200 Subject: [PATCH] [partition] Avoid uninitialized variable - if the partition size is invalid, then warn about it but do not print the (uninitialized) size of the partition. - shuffle code to continue earlier, allowing the "good path" code to be out-dented. --- .../partition/core/PartitionLayout.cpp | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 1b4e49bd6..d42e7b568 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -172,32 +172,30 @@ PartitionLayout::execute( Device* dev, // Let's check if we have enough space for each partSize for ( const auto& part : qAsConst( m_partLayout ) ) { - qint64 size; - // Calculate partition size - - if ( part.partSize.isValid() ) + if ( !part.partSize.isValid() ) { - // We need to ignore the percent-defined - if ( part.partSize.unit() != CalamaresUtils::Partition::SizeUnit::Percent ) - { - size = part.partSize.toSectors( totalSize, dev->logicalSize() ); - } - else - { - if ( part.partMinSize.isValid() ) - { - size = part.partMinSize.toSectors( totalSize, dev->logicalSize() ); - } - else - { - size = 0; - } - } + cWarning() << "Partition" << part.partMountPoint << "size is invalid, skipping..."; + continue; + } + + // Calculate partition size: Rely on "possibly uninitialized use" + // warnings to ensure that all the cases are covered below. + qint64 size; + // We need to ignore the percent-defined until later + if ( part.partSize.unit() != CalamaresUtils::Partition::SizeUnit::Percent ) + { + size = part.partSize.toSectors( totalSize, dev->logicalSize() ); } else { - cWarning() << "Partition" << part.partMountPoint << "size (" << size << "sectors) is invalid, skipping..."; - continue; + if ( part.partMinSize.isValid() ) + { + size = part.partMinSize.toSectors( totalSize, dev->logicalSize() ); + } + else + { + size = 0; + } } partSizeMap.insert( &part, size );