From de850125aaffeebb6530214047bacd97feed32f9 Mon Sep 17 00:00:00 2001 From: Dmitry Zagorodnev Date: Mon, 20 Feb 2023 14:29:32 +0300 Subject: [PATCH] Fix: lrcompletermodel access to null ptr --- limereport/scripteditor/lrcompletermodel.cpp | 19 ++++++++++--------- limereport/scripteditor/lrcompletermodel.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/limereport/scripteditor/lrcompletermodel.cpp b/limereport/scripteditor/lrcompletermodel.cpp index 29c7116..70299f6 100644 --- a/limereport/scripteditor/lrcompletermodel.cpp +++ b/limereport/scripteditor/lrcompletermodel.cpp @@ -22,16 +22,17 @@ QModelIndex CompleterModel::index(int row, int column, const QModelIndex &parent return createIndex(row, column, parentItem->child(row)); } -QModelIndex CompleterModel::parent(const QModelIndex &child) const -{ - if (child.isValid()){ - CompleterItem *childItem = static_cast(child.internalPointer()); - CompleterItem *parentItem = childItem->parent(); - if (parentItem != &m_root) { - return indexFromItem(parentItem); - } +QModelIndex CompleterModel::parent(const QModelIndex &child) const { + if(child.isValid()) { + if(CompleterItem *childItem = static_cast(child.internalPointer()); + childItem) { + CompleterItem *parentItem = childItem->parent(); + if(parentItem != &m_root) { + return indexFromItem(parentItem); + } } - return QModelIndex(); + } + return QModelIndex(); } int CompleterModel::rowCount(const QModelIndex &parent) const diff --git a/limereport/scripteditor/lrcompletermodel.h b/limereport/scripteditor/lrcompletermodel.h index eeab147..9611e5d 100644 --- a/limereport/scripteditor/lrcompletermodel.h +++ b/limereport/scripteditor/lrcompletermodel.h @@ -35,7 +35,7 @@ public: void appendRow(CompleterItem* child); void appendRows(const QList &children); private: - CompleterItem* m_parent; + CompleterItem* m_parent{nullptr}; QVector > m_children; QString m_text; QIcon m_icon;