From 5f2857f12ae239f4393866d9cc409c2b33a0a437 Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 2 Nov 2019 14:28:48 +0100 Subject: [PATCH] Fix crashes from accessing invalid pointers. --- pglab/QueryTool.cpp | 5 ++++- pglablib/model/TypeSelectionItemModel.cpp | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pglab/QueryTool.cpp b/pglab/QueryTool.cpp index 06ca55c..a021a92 100644 --- a/pglab/QueryTool.cpp +++ b/pglab/QueryTool.cpp @@ -41,7 +41,10 @@ QueryTool::QueryTool(IDatabaseWindow *context, QWidget *parent) ui->queryEdit->setFont(UserConfiguration::instance()->codeFont()); highlighter = new SqlSyntaxHighlighter(ui->queryEdit->document()); - highlighter->setTypes(*m_catalog->types()); + auto types = m_catalog->types(); + if (types) { + highlighter->setTypes(*types); + } connect(ui->queryEdit, &QPlainTextEdit::textChanged, this, &QueryTool::queryTextChanged); diff --git a/pglablib/model/TypeSelectionItemModel.cpp b/pglablib/model/TypeSelectionItemModel.cpp index a148739..2a85da5 100644 --- a/pglablib/model/TypeSelectionItemModel.cpp +++ b/pglablib/model/TypeSelectionItemModel.cpp @@ -47,12 +47,14 @@ void TypeSelectionItemModel::setTypeList(std::shared_ptr { beginResetModel(); m_types.clear(); - for (const auto &e : *types) { - if (e.category != TypCategory::Array && e.type != "c") { - m_types.push_back(e.objectName()); + if (types) { + for (const auto &e : *types) { + if (e.category != TypCategory::Array && e.type != "c") { + m_types.push_back(e.objectName()); + } } + std::sort(m_types.begin(), m_types.end()); } - std::sort(m_types.begin(), m_types.end()); //emit dataChanged(this->createIndex(0, 0), this->createIndex(types->count(), 0), QVector() << Qt::DisplayRole); endResetModel(); }