From 5ea92a921750a89d543fd64a5dd82238dce5b5a5 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Tue, 7 Feb 2023 20:36:25 +0200 Subject: [PATCH] Fix coverity warning (#1154) IB-7550 Signed-off-by: Raul Metsma --- .github/workflows/build.yml | 4 ++-- client/dialogs/KeyDialog.cpp | 28 +++++++++++++--------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 393fb6f2f..84bf9e654 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -217,7 +217,7 @@ jobs: coverity: name: Run Coverity tests if: github.repository == 'open-eid/DigiDoc4-Client' && contains(github.ref, 'coverity_scan') - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 env: TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} PROJECTNAME: open-eid/DigiDoc4-Client @@ -262,7 +262,7 @@ jobs: codeql: name: Run CodeQL tests if: github.repository == 'open-eid/DigiDoc4-Client' - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 permissions: security-events: write steps: diff --git a/client/dialogs/KeyDialog.cpp b/client/dialogs/KeyDialog.cpp index bfc3583ba..28392635e 100644 --- a/client/dialogs/KeyDialog.cpp +++ b/client/dialogs/KeyDialog.cpp @@ -26,15 +26,17 @@ #include "effects/Overlay.h" #include "dialogs/CertificateDetails.h" +#include + KeyDialog::KeyDialog( const CKey &k, QWidget *parent ) : QDialog( parent ) { - Ui::KeyDialog *d = new Ui::KeyDialog; + auto d = std::make_unique(); d->setupUi(this); #if defined (Q_OS_WIN) d->buttonLayout->setDirection(QBoxLayout::RightToLeft); #endif - setWindowFlags( Qt::Dialog | Qt::CustomizeWindowHint ); + setWindowFlag(Qt::CustomizeWindowHint); new Overlay(this, parent->topLevelWidget()); QFont condensed = Styles::font(Styles::Condensed, 12); @@ -46,31 +48,27 @@ KeyDialog::KeyDialog( const CKey &k, QWidget *parent ) d->view->setHeaderLabels({tr("Attribute"), tr("Value")}); connect(d->close, &QPushButton::clicked, this, &KeyDialog::accept); - connect(d->showCert, &QPushButton::clicked, this, [=] { - CertificateDetails::showCertificate(SslCertificate(k.cert), this); + connect(d->showCert, &QPushButton::clicked, this, [this, cert=k.cert] { + CertificateDetails::showCertificate(cert, this); }); auto addItem = [&](const QString ¶meter, const QString &value) { - QTreeWidgetItem *i = new QTreeWidgetItem(d->view); + if(value.isEmpty()) + return; + auto *i = new QTreeWidgetItem(d->view); i->setText(0, parameter); i->setText(1, value); d->view->addTopLevelItem(i); }; addItem(tr("Recipient"), k.recipient); - if(!k.method.isEmpty()) - addItem(tr("Crypto method"), k.method); - if(!k.agreement.isEmpty()) - addItem(tr("Agreement method"), k.agreement); - if(!k.derive.isEmpty()) - addItem(tr("Key derivation method"), k.derive); - if(!k.concatDigest.isEmpty()) - addItem(tr("ConcatKDF digest method"), k.concatDigest); - //addItem( tr("ID"), k.id ); + addItem(tr("Crypto method"), k.method); + addItem(tr("Agreement method"), k.agreement); + addItem(tr("Key derivation method"), k.derive); + addItem(tr("ConcatKDF digest method"), k.concatDigest); addItem(tr("Expiry date"), k.cert.expiryDate().toLocalTime().toString(QStringLiteral("dd.MM.yyyy hh:mm:ss"))); addItem(tr("Issuer"), SslCertificate(k.cert).issuerInfo(QSslCertificate::CommonName)); d->view->resizeColumnToContents( 0 ); if(!k.agreement.isEmpty()) adjustSize(); - delete d; }