Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/dialogs/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "muParserDef.h"
#include "qcustomplot/qcustomplot.h"

#include "models/adapterdata.h"
#include "models/settingsmodel.h"
#include "util/updatenotify.h"
#include "util/util.h"
#include "util/version.h"
Expand All @@ -12,9 +14,8 @@
#include <QLibraryInfo>
#include <QUrl>

AboutDialog::AboutDialog(UpdateNotify *pUpdateNotify, QWidget *parent) :
QDialog(parent),
_pUi(new Ui::AboutDialog)
AboutDialog::AboutDialog(UpdateNotify* pUpdateNotify, SettingsModel* pSettingsModel, QWidget* parent)
: QDialog(parent), _pUi(new Ui::AboutDialog)
{
_pUi->setupUi(this);

Expand All @@ -25,6 +26,7 @@ AboutDialog::AboutDialog(UpdateNotify *pUpdateNotify, QWidget *parent) :
connect(_pUi->btnLicense, &QPushButton::clicked, this, &AboutDialog::openLicense);

setVersionInfo();
setAdapterVersionInfo(pSettingsModel);
setLibraryVersionInfo();

showVersionUpdate(pUpdateNotify);
Expand Down Expand Up @@ -55,7 +57,8 @@ void AboutDialog::showVersionUpdate(UpdateNotify* updateNotify)
{
QString updateTxt;

updateTxt.append(QString("Update available: <a href=\'%1\'>v%2</a>").arg(updateNotify->link().toString(), updateNotify->version()));
updateTxt.append(QString("Update available: <a href=\'%1\'>v%2</a>")
.arg(updateNotify->link().toString(), updateNotify->version()));

updateTxt.append("<br/>");
_pUi->lblUpdate->setText(updateTxt);
Expand Down Expand Up @@ -91,6 +94,24 @@ void AboutDialog::setVersionInfo()
_pUi->lblVersion->setText(QString(tr("v%1%2 (%3)")).arg(Util::currentVersion(), betaTxt, arch));
}

void AboutDialog::setAdapterVersionInfo(SettingsModel* pSettingsModel)
{
QString versionTxt;

for (const QString& id : pSettingsModel->adapterIds())
{
const QString version = pSettingsModel->adapterData(id)->version();
if (!version.isEmpty())
{
versionTxt = QString(tr("Adapter: v%1")).arg(version);
break;
}
}

_pUi->lblAdapterVersion->setVisible(!versionTxt.isEmpty());
_pUi->lblAdapterVersion->setText(versionTxt);
}
Comment on lines +97 to +113
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard pSettingsModel before use to prevent a crash.

Line 101 dereferences pSettingsModel unconditionally. If a null pointer reaches this path, About dialog construction will fail.

💡 Proposed fix
 void AboutDialog::setAdapterVersionInfo(SettingsModel* pSettingsModel)
 {
+    if (pSettingsModel == nullptr)
+    {
+        _pUi->lblAdapterVersion->clear();
+        _pUi->lblAdapterVersion->setVisible(false);
+        return;
+    }
+
     QString versionTxt;
 
     for (const QString& id : pSettingsModel->adapterIds())
     {
         const QString version = pSettingsModel->adapterData(id)->version();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/dialogs/aboutdialog.cpp` around lines 97 - 113,
AboutDialog::setAdapterVersionInfo currently dereferences pSettingsModel without
a null check; add a guard at the start of the function (e.g., if
(!pSettingsModel) { _pUi->lblAdapterVersion->setVisible(false);
_pUi->lblAdapterVersion->setText(QString()); return; }) so you don’t call
pSettingsModel->adapterIds() or adapterData() when pSettingsModel is null, and
ensure _pUi->lblAdapterVersion visibility/text are set to safe defaults when
returning early.


void AboutDialog::setLibraryVersionInfo()
{
QString qtVersion(QLibraryInfo::version().toString());
Expand All @@ -105,4 +126,3 @@ void AboutDialog::setLibraryVersionInfo()

_pUi->textAbout->setHtml(aboutText);
}

7 changes: 4 additions & 3 deletions src/dialogs/aboutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// Forward declaration
class UpdateNotify;
class SettingsModel;

namespace Ui {
class AboutDialog;
Expand All @@ -15,7 +16,7 @@ class AboutDialog : public QDialog
Q_OBJECT

public:
explicit AboutDialog(UpdateNotify* pUpdateNotify, QWidget *parent = nullptr);
explicit AboutDialog(UpdateNotify* pUpdateNotify, SettingsModel* pSettingsModel, QWidget* parent = nullptr);
~AboutDialog();

private slots:
Expand All @@ -25,10 +26,10 @@ private slots:
private:
void showVersionUpdate(UpdateNotify* updateNotify);
void setVersionInfo();
void setAdapterVersionInfo(SettingsModel* pSettingsModel);
void setLibraryVersionInfo();

Ui::AboutDialog * _pUi;

Ui::AboutDialog* _pUi;
};

#endif // ABOUTDIALOG_H
17 changes: 16 additions & 1 deletion src/dialogs/aboutdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,22 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="2">
<item row="4" column="1" colspan="2">
<widget class="QLabel" name="lblAdapterVersion">
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
<item row="5" column="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void MainWindow::selectImageExportFile()

void MainWindow::showAbout()
{
AboutDialog aboutDialog(_pUpdateNotify, this);
AboutDialog aboutDialog(_pUpdateNotify, _pSettingsModel, this);

aboutDialog.exec();
}
Expand Down