PartitionModule: avoid nullptr crashes

Fix up iterator code so that it handles nullptr better.
This avoids part of #686.
This commit is contained in:
Adriaan de Groot 2017-06-14 11:39:53 -04:00 committed by Philip
parent 2dbcee346d
commit 8823938c8f
2 changed files with 7 additions and 2 deletions

View File

@ -157,9 +157,9 @@ PartitionCoreModule::doInit()
// Remove the device which contains / from the list
for ( QList< Device* >::iterator it = devices.begin(); it != devices.end(); )
if ( hasRootPartition( *it ) ||
if ( *it && ( hasRootPartition( *it ) ||
(*it)->deviceNode().startsWith( "/dev/zram") ||
isIso9660( *it ) )
isIso9660( *it ) ) )
it = devices.erase( it );
else
++it;

View File

@ -2,6 +2,7 @@
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -83,6 +84,8 @@ PartitionIterator::operator!=( const PartitionIterator& other ) const
PartitionIterator
PartitionIterator::begin( Device* device )
{
if ( !device )
return PartitionIterator( nullptr );
Q_ASSERT(device);
PartitionTable* table = device->partitionTable();
if ( !table )
@ -106,6 +109,8 @@ PartitionIterator::begin( PartitionTable* table )
PartitionIterator
PartitionIterator::end( Device* device )
{
if ( !device )
return PartitionIterator( nullptr );
PartitionTable* table = device->partitionTable();
if ( !table )
return PartitionIterator( nullptr );