Commit f4ce2ec7 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Replace assert() with Q_ASSERT()

Fixes 'lambda-expression in unevaluated context' error in some places and generally
switches to Q_ASSERT, which is what we should be using in a Qt app anyway.
parent 442ca9ad
......@@ -47,7 +47,6 @@
#include <KLocalizedString>
#include "kleopatra_debug.h"
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -152,7 +151,7 @@ void AddUserIDCommand::doStart()
d->key = keys.front();
d->ensureDialogCreated();
assert(d->dialog);
Q_ASSERT(d->dialog);
const UserID uid = d->key.userID(0);
......@@ -165,7 +164,7 @@ void AddUserIDCommand::doStart()
void AddUserIDCommand::Private::slotDialogAccepted()
{
assert(dialog);
Q_ASSERT(dialog);
createJob();
if (!job) {
......@@ -220,7 +219,7 @@ void AddUserIDCommand::Private::ensureDialogCreated()
void AddUserIDCommand::Private::createJob()
{
assert(!job);
Q_ASSERT(!job);
const auto backend = (key.protocol() == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime();
if (!backend) {
......
......@@ -53,7 +53,6 @@
#include <KLocalizedString>
#include "kleopatra_debug.h"
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -247,7 +246,7 @@ void CertifyCertificateCommand::doStart()
}
d->ensureDialogCreated();
assert(d->dialog);
Q_ASSERT(d->dialog);
d->dialog->setCertificateToCertify(d->key());
d->dialog->setSelectedUserIDs(d->uids);
d->dialog->setCertificatesWithSecretKeys(secKeys);
......@@ -272,10 +271,10 @@ void CertifyCertificateCommand::Private::slotResult(const Error &err)
void CertifyCertificateCommand::Private::slotCertificationPrepared()
{
assert(dialog);
Q_ASSERT(dialog);
createJob();
assert(job);
Q_ASSERT(job);
job->setExportable(dialog->exportableCertificationSelected());
job->setNonRevocable(dialog->nonRevocableCertificationSelected());
job->setUserIDsToSign(dialog->selectedUserIDs());
......@@ -318,9 +317,9 @@ void CertifyCertificateCommand::Private::createJob()
disconnect(dialog, SIGNAL(certificationPrepared()), q, SLOT(slotCertificationPrepared()));
}
assert(!job);
Q_ASSERT(!job);
assert(key().protocol() == OpenPGP);
Q_ASSERT(key().protocol() == OpenPGP);
const auto backend = QGpgME::openpgp();
if (!backend) {
return;
......
......@@ -50,7 +50,6 @@
#include <QDateTime>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -157,7 +156,7 @@ void ChangeExpiryCommand::doStart()
d->key = keys.front();
d->ensureDialogCreated();
assert(d->dialog);
Q_ASSERT(d->dialog);
const Subkey subkey = d->key.subkey(0);
d->dialog->setDateOfExpiry(subkey.neverExpires() ? QDate() : QDateTime::fromTime_t(d->key.subkey(0).expirationTime()).date());
d->dialog->show();
......@@ -166,7 +165,7 @@ void ChangeExpiryCommand::doStart()
void ChangeExpiryCommand::Private::slotDialogAccepted()
{
assert(dialog);
Q_ASSERT(dialog);
static const QTime END_OF_DAY(23, 59, 59); // not used, so as good as any
......@@ -175,7 +174,7 @@ void ChangeExpiryCommand::Private::slotDialogAccepted()
qCDebug(KLEOPATRA_LOG) << "expiry" << expiry;
createJob();
assert(job);
Q_ASSERT(job);
if (const Error err = job->start(key, expiry)) {
showErrorDialog(err);
......@@ -225,7 +224,7 @@ void ChangeExpiryCommand::Private::ensureDialogCreated()
void ChangeExpiryCommand::Private::createJob()
{
assert(!job);
Q_ASSERT(!job);
const auto backend = (key.protocol() == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime();
if (!backend) {
......
......@@ -48,7 +48,6 @@
#include <KLocalizedString>
#include "kleopatra_debug.h"
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -153,7 +152,7 @@ void ChangeOwnerTrustCommand::doStart()
}
d->ensureDialogCreated();
assert(d->dialog);
Q_ASSERT(d->dialog);
d->dialog->setHasSecretKey(key.hasSecret());
d->dialog->setFormattedCertificateName(Formatting::formatForComboBox(key));
......@@ -165,14 +164,14 @@ void ChangeOwnerTrustCommand::doStart()
void ChangeOwnerTrustCommand::Private::slotDialogAccepted()
{
assert(dialog);
Q_ASSERT(dialog);
const Key::OwnerTrust trust = dialog->ownerTrust();
qCDebug(KLEOPATRA_LOG) << "trust " << trust;
createJob();
assert(job);
Q_ASSERT(job);
if (const Error err = job->start(key(), trust)) {
showErrorDialog(err);
......@@ -222,7 +221,7 @@ void ChangeOwnerTrustCommand::Private::ensureDialogCreated()
void ChangeOwnerTrustCommand::Private::createJob()
{
assert(!job);
Q_ASSERT(!job);
const auto backend = (key().protocol() == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime();
if (!backend) {
......
......@@ -48,7 +48,6 @@
#include <gpg-error.h>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -185,7 +184,7 @@ void ChangePassphraseCommand::doCancel()
void ChangePassphraseCommand::Private::createJob()
{
assert(!job);
Q_ASSERT(!job);
const auto backend = (key.protocol() == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime();
if (!backend) {
......
......@@ -56,7 +56,6 @@
#include <gpgme++/key.h>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -140,7 +139,7 @@ ChangeRootTrustCommand::ChangeRootTrustCommand(QAbstractItemView *v, KeyListCont
ChangeRootTrustCommand::ChangeRootTrustCommand(const Key &key, KeyListController *p)
: Command(new Private(this, p))
{
assert(!key.isNull());
Q_ASSERT(!key.isNull());
d->init();
setKey(key);
}
......@@ -148,7 +147,7 @@ ChangeRootTrustCommand::ChangeRootTrustCommand(const Key &key, KeyListController
ChangeRootTrustCommand::ChangeRootTrustCommand(const Key &key, QAbstractItemView *v, KeyListController *p)
: Command(v, new Private(this, p))
{
assert(!key.isNull());
Q_ASSERT(!key.isNull());
d->init();
setKey(key);
}
......@@ -157,7 +156,7 @@ ChangeRootTrustCommand::~ChangeRootTrustCommand() {}
void ChangeRootTrustCommand::setTrust(Key::OwnerTrust trust)
{
assert(!d->isRunning());
Q_ASSERT(!d->isRunning());
const QMutexLocker locker(&d->mutex);
d->trust = trust;
}
......@@ -170,7 +169,7 @@ Key::OwnerTrust ChangeRootTrustCommand::trust() const
void ChangeRootTrustCommand::setTrustListFile(const QString &trustListFile)
{
assert(!d->isRunning());
Q_ASSERT(!d->isRunning());
const QMutexLocker locker(&d->mutex);
d->trustListFile = trustListFile;
}
......
......@@ -56,7 +56,6 @@
#include <algorithm>
#include <vector>
#include <cassert>
using namespace GpgME;
using namespace Kleo;
......@@ -305,7 +304,7 @@ void DeleteCertificatesCommand::doStart()
void DeleteCertificatesCommand::Private::slotDialogAccepted()
{
std::vector<Key> keys = dialog->keys();
assert(!keys.empty());
Q_ASSERT(!keys.empty());
auto pgpBegin = keys.begin();
auto pgpEnd = std::stable_partition(pgpBegin, keys.end(),
......@@ -339,7 +338,7 @@ void DeleteCertificatesCommand::Private::slotDialogAccepted()
}
}
assert(!openpgp.empty() || !cms.empty());
Q_ASSERT(!openpgp.empty() || !cms.empty());
pgpKeys.swap(openpgp);
cmsKeys.swap(cms);
......@@ -359,12 +358,12 @@ void DeleteCertificatesCommand::Private::slotDialogAccepted()
void DeleteCertificatesCommand::Private::startDeleteJob(GpgME::Protocol protocol)
{
assert(protocol != GpgME::UnknownProtocol);
Q_ASSERT(protocol != GpgME::UnknownProtocol);
const std::vector<Key> &keys = protocol == CMS ? cmsKeys : pgpKeys;
const auto backend = (protocol == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime();
assert(backend);
Q_ASSERT(backend);
std::unique_ptr<MultiDeleteJob> job(new MultiDeleteJob(backend));
......@@ -388,7 +387,7 @@ void DeleteCertificatesCommand::Private::startDeleteJob(GpgME::Protocol protocol
void DeleteCertificatesCommand::Private::showErrorsAndFinish()
{
assert(!pgpJob); assert(!cmsJob);
Q_ASSERT(!pgpJob); Q_ASSERT(!cmsJob);
if (pgpError || cmsError) {
QString pgpErrorString;
......
......@@ -39,7 +39,6 @@
#include "kleopatra_debug.h"
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -129,7 +128,7 @@ DetailsCommand::DetailsCommand(QAbstractItemView *v, KeyListController *p)
DetailsCommand::DetailsCommand(const Key &key, KeyListController *p)
: Command(new Private(this, p))
{
assert(!key.isNull());
Q_ASSERT(!key.isNull());
d->init();
setKey(key);
}
......@@ -137,7 +136,7 @@ DetailsCommand::DetailsCommand(const Key &key, KeyListController *p)
DetailsCommand::DetailsCommand(const Key &key, QAbstractItemView *v, KeyListController *p)
: Command(v, new Private(this, p))
{
assert(!key.isNull());
Q_ASSERT(!key.isNull());
d->init();
setKey(key);
}
......
......@@ -56,7 +56,6 @@
#include <algorithm>
#include <vector>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Dialogs;
......@@ -168,7 +167,7 @@ void ExportCertificateCommand::doStart()
std::vector<Key> openpgp, cms;
std::copy(keys.begin(), firstCms, std::back_inserter(openpgp));
std::copy(firstCms, keys.end(), std::back_inserter(cms));
assert(!openpgp.empty() || !cms.empty());
Q_ASSERT(!openpgp.empty() || !cms.empty());
const bool haveBoth = !cms.empty() && !openpgp.empty();
const GpgME::Protocol prot = haveBoth ? UnknownProtocol : (!cms.empty() ? CMS : OpenPGP);
if (!d->requestFileNames(prot)) {
......@@ -234,16 +233,16 @@ bool ExportCertificateCommand::Private::requestFileNames(GpgME::Protocol protoco
void ExportCertificateCommand::Private::startExportJob(GpgME::Protocol protocol, const std::vector<Key> &keys)
{
assert(protocol != GpgME::UnknownProtocol);
Q_ASSERT(protocol != GpgME::UnknownProtocol);
const QGpgME::Protocol *const backend = (protocol == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime();
assert(backend);
Q_ASSERT(backend);
const QString fileName = fileNames[protocol];
const bool binary = protocol == GpgME::OpenPGP
? fileName.endsWith(QStringLiteral(".gpg"), Qt::CaseInsensitive) || fileName.endsWith(QStringLiteral(".pgp"), Qt::CaseInsensitive)
: fileName.endsWith(QStringLiteral(".der"), Qt::CaseInsensitive);
std::unique_ptr<ExportJob> job(backend->publicKeyExportJob(!binary));
assert(job.get());
Q_ASSERT(job.get());
connect(job.get(), SIGNAL(result(GpgME::Error,QByteArray)),
q, SLOT(exportResult(GpgME::Error,QByteArray)));
......@@ -273,7 +272,7 @@ void ExportCertificateCommand::Private::startExportJob(GpgME::Protocol protocol,
void ExportCertificateCommand::Private::showError(const GpgME::Error &err)
{
assert(err);
Q_ASSERT(err);
const QString msg = i18n("<qt><p>An error occurred while trying to export "
"the certificate:</p>"
"<p><b>%1</b></p></qt>",
......@@ -310,10 +309,10 @@ static bool write_complete(QIODevice &iod, const QByteArray &data)
void ExportCertificateCommand::Private::exportResult(const GpgME::Error &err, const QByteArray &data)
{
assert(jobsPending > 0);
Q_ASSERT(jobsPending > 0);
--jobsPending;
assert(outFileForSender.contains(q->sender()));
Q_ASSERT(outFileForSender.contains(q->sender()));
const QString outFile = outFileForSender[q->sender()];
if (err) {
......
......@@ -57,7 +57,6 @@
#include <KSharedConfig>
#include <memory>
#include <cassert>
using namespace GpgME;
using namespace Kleo;
......
......@@ -65,7 +65,6 @@
#include <memory>
#include <algorithm>
#include <cassert>
#include <map>
#include <set>
......@@ -130,7 +129,7 @@ protected:
// 0. Keep parents of matching children:
//
const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
assert(index.isValid());
Q_ASSERT(index.isValid());
for (int i = 0, end = sourceModel()->rowCount(index); i != end; ++i)
if (filterAcceptsRow(i, index)) {
return true;
......@@ -148,7 +147,7 @@ protected:
private:
void updateFindCache(const std::vector<ImportResult> &results, const QStringList &ids)
{
assert(results.size() == static_cast<unsigned>(ids.size()));
Q_ASSERT(results.size() == static_cast<unsigned>(ids.size()));
m_importsByFingerprint.clear();
m_idsByFingerprint.clear();
m_results = results;
......@@ -310,7 +309,7 @@ static QString make_report(const std::vector<ImportResult> &res, const QString &
static QString make_message_report(const std::vector<ImportResult> &res, const QStringList &ids)
{
assert(res.size() == static_cast<unsigned>(ids.size()));
Q_ASSERT(res.size() == static_cast<unsigned>(ids.size()));
if (res.empty()) {
return i18n("No imports (should not happen, please report a bug).");
......@@ -407,8 +406,8 @@ void ImportCertificatesCommand::Private::showDetails(const std::vector<ImportRes
static QString make_error_message(const Error &err, const QString &id)
{
assert(err);
assert(!err.isCanceled());
Q_ASSERT(err);
Q_ASSERT(!err.isCanceled());
return id.isEmpty()
? i18n("<qt><p>An error occurred while trying "
"to import the certificate:</p>"
......@@ -548,7 +547,7 @@ void ImportCertificatesCommand::Private::tryToFinish()
static std::unique_ptr<ImportJob> get_import_job(GpgME::Protocol protocol)
{
assert(protocol != UnknownProtocol);
Q_ASSERT(protocol != UnknownProtocol);
if (const auto backend = (protocol == GpgME::OpenPGP ? QGpgME::openpgp() : QGpgME::smime())) {
return std::unique_ptr<ImportJob>(backend->importJob());
} else {
......@@ -558,7 +557,7 @@ static std::unique_ptr<ImportJob> get_import_job(GpgME::Protocol protocol)
void ImportCertificatesCommand::Private::startImport(GpgME::Protocol protocol, const QByteArray &data, const QString &id)
{
assert(protocol != UnknownProtocol);
Q_ASSERT(protocol != UnknownProtocol);
if (std::find(nonWorkingProtocols.cbegin(), nonWorkingProtocols.cend(), protocol) != nonWorkingProtocols.cend()) {
return;
......@@ -589,7 +588,7 @@ void ImportCertificatesCommand::Private::startImport(GpgME::Protocol protocol, c
static std::unique_ptr<ImportFromKeyserverJob> get_import_from_keyserver_job(GpgME::Protocol protocol)
{
assert(protocol != UnknownProtocol);
Q_ASSERT(protocol != UnknownProtocol);
if (const auto backend = (protocol == GpgME::OpenPGP ? QGpgME::openpgp() : QGpgME::smime())) {
return std::unique_ptr<ImportFromKeyserverJob>(backend->importFromKeyserverJob());
} else {
......@@ -599,7 +598,7 @@ static std::unique_ptr<ImportFromKeyserverJob> get_import_from_keyserver_job(Gpg
void ImportCertificatesCommand::Private::startImport(GpgME::Protocol protocol, const std::vector<Key> &keys, const QString &id)
{
assert(protocol != UnknownProtocol);
Q_ASSERT(protocol != UnknownProtocol);
if (std::find(nonWorkingProtocols.cbegin(), nonWorkingProtocols.cend(), protocol) != nonWorkingProtocols.cend()) {
return;
......
......@@ -46,7 +46,6 @@
#include <KLocalizedString>
#include <cassert>
#include <gpgme++/gpgmepp_version.h>
#if GPGMEPP_VERSION > 0x10801
......
......@@ -63,7 +63,6 @@
#include <vector>
#include <map>
#include <algorithm>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -205,7 +204,7 @@ void LookupCertificatesCommand::doStart()
}
d->createDialog();
assert(d->dialog);
Q_ASSERT(d->dialog);
// if we have a prespecified query, load it into find field
// and start the search
......@@ -317,8 +316,8 @@ void LookupCertificatesCommand::Private::slotImportRequested(const std::vector<K
{
dialog = nullptr;
assert(!keys.empty());
assert(std::none_of(keys.cbegin(), keys.cend(), [](const Key &key) { return key.isNull(); }));
Q_ASSERT(!keys.empty());
Q_ASSERT(std::none_of(keys.cbegin(), keys.cend(), [](const Key &key) { return key.isNull(); }));
std::vector<Key> pgp, cms;
pgp.reserve(keys.size());
......
......@@ -37,7 +37,6 @@
#include <newcertificatewizard/newcertificatewizard.h>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......@@ -136,7 +135,7 @@ void NewCertificateCommand::doStart()
{
d->ensureDialogCreated();
assert(d->dialog);
Q_ASSERT(d->dialog);
if (d->protocol != UnknownProtocol) {
d->dialog->setProtocol(d->protocol);
......
......@@ -41,7 +41,6 @@
#include <KLocalizedString>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
......
......@@ -47,7 +47,6 @@
#include <QStringList>
#include <cassert>
#include <exception>
using namespace Kleo;
......@@ -182,7 +181,7 @@ Policy SignEncryptFilesCommand::signingPolicy() const
const unsigned int mode = d->controller.operationMode();
switch (mode & SignEncryptFilesController::SignMask) {
default:
assert(!"This should not happen!");
Q_ASSERT(!"This should not happen!");
return NoPolicy;
case SignEncryptFilesController::SignAllowed:
return Allow;
......@@ -219,7 +218,7 @@ Policy SignEncryptFilesCommand::encryptionPolicy() const
const unsigned int mode = d->controller.operationMode();
switch (mode & SignEncryptFilesController::EncryptMask) {
default:
assert(!"This should not happen!");
Q_ASSERT(!"This should not happen!");
return NoPolicy;
case SignEncryptFilesController::EncryptAllowed:
return Allow;
......@@ -260,7 +259,7 @@ Policy SignEncryptFilesCommand::archivePolicy() const
case SignEncryptFilesController::ArchiveDisallowed:
return Deny;
default:
assert(!"This should not happen!");
Q_ASSERT(!"This should not happen!");
return NoPolicy;
}
}
......
......@@ -60,7 +60,6 @@
#include <QRegularExpression>
#include <algorithm>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Config;
......@@ -504,7 +503,7 @@ void AppearanceConfigWidget::save()
#endif
for (int i = 0, end = std::min(groups.size(), d->categoriesLV->count()); i != end; ++i) {
const QListWidgetItem *const item = d->categoriesLV->item(i);
assert(item);
Q_ASSERT(item);
KConfigGroup group(config, groups[i]);
save_to_config(item, group);
}
......
......@@ -364,7 +364,7 @@ void AutoDecryptVerifyFilesController::cancel()
void AutoDecryptVerifyFilesController::doTaskDone(const Task *task, const std::shared_ptr<const Task::Result> &result)
{
assert(task);
Q_ASSERT(task);
Q_UNUSED(task);
// We could just delete the tasks here, but we can't use
......
......@@ -48,7 +48,6 @@
#include <algorithm>
#include <iterator>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Crypto;
......@@ -129,7 +128,7 @@ private:
KConfigBasedRecipientPreferences::Private::Private(const KSharedConfigPtr &config, KConfigBasedRecipientPreferences *qq) : q(qq), m_config(config), m_parsed(false), m_dirty(false)
{
assert(m_config);
Q_ASSERT(m_config);
}
KConfigBasedRecipientPreferences::Private::~Private()
......@@ -229,7 +228,7 @@ private:
KConfigBasedSigningPreferences::Private::Private(const KSharedConfigPtr &config, KConfigBasedSigningPreferences *qq) : q(qq), m_config(config), m_parsed(false), m_dirty(false)
{
assert(m_config);
Q_ASSERT(m_config);
}
void KConfigBasedSigningPreferences::Private::ensurePrefsParsed() const
......
......@@ -34,7 +34,6 @@
#include "controller.h"
#include <cassert>
using namespace Kleo;
using namespace Kleo::Crypto;
......@@ -78,7 +77,7 @@ void Controller::taskDone(const std::shared_ptr<const Task::Result> &result)
d->lastErrorString = result->errorString();
}
const Task *task = qobject_cast<const Task *>(sender());
assert(task);
Q_ASSERT(task);
doTaskDone(task, result);
}
......@@ -86,7 +85,7 @@ void Controller::doTaskDone(const Task *, const std::shared_ptr<const Task::Resu