[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kpackage] src/kpackagetool: Avoid potential access of .last() on empty list
From:       David Edmundson <kde () davidedmundson ! co ! uk>
Date:       2016-11-22 10:40:40
Message-ID: E1c98VE-0002sg-De () code ! kde ! org
[Download RAW message or body]

Git commit 284dddb0f38f43211501890ec2f63db8177dd408 by David Edmundson.
Committed on 22/11/2016 at 10:40.
Pushed by davidedmundson into branch 'master'.

Avoid potential access of .last() on empty list

locateAll can return nothing, therefore we can't always call .last() on
it.

Existing code should be able to handle an empty package root as the user
could also also have provided a broken package root as an argument.

REVIEW: 129436

M  +3    -1    src/kpackagetool/kpackagetool.cpp

http://commits.kde.org/kpackage/284dddb0f38f43211501890ec2f63db8177dd408

diff --git a/src/kpackagetool/kpackagetool.cpp b/src/kpackagetool/kpackagetool.cpp
index 4227ebf..18a9370 100644
--- a/src/kpackagetool/kpackagetool.cpp
+++ b/src/kpackagetool/kpackagetool.cpp
@@ -510,7 +510,9 @@ QString PackageTool::findPackageRoot(const QString &pluginName, \
                const QString &p
         //qDebug() << "(set via arg) d->packageRoot is: " << d->packageRoot;
     } else if (d->parser->isSet(QStringLiteral("global"))) {
         auto const paths = \
QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, d->packageRoot, \
                QStandardPaths::LocateDirectory);
-        packageRoot = paths.last();
+        if (!paths.isEmpty()) {
+            packageRoot = paths.last();
+        }
     } else {
         packageRoot = \
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + \
QLatin1Char('/') + d->packageRoot;  }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic