summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2019-02-26 21:30:48 +0100
committerDominik Haumann <dhaumann@kde.org>2019-02-27 06:36:59 +0000
commit16cb578a8d102f1c937dcc3a07b88b24c9ed685a (patch)
treec77436d40e98c43b41906cf0cec854bc2dd93838
parent96404f7ac89244c944adaa7533c6292e7a614311 (diff)
QSyntaxHighlighter: Fix crash when parent is a nullptr
QSyntaxHighlighter has the follwoing constructor taking a QObject QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent) : QObject(*new QSyntaxHighlighterPrivate, parent) { if (parent->inherits("QTextEdit")) { // ... } } Typically, a 'parent' refers to the parent/child hierarchy in Qt and is allowed to be a nullptr. However, in this case, passing a nullptr will lead to a crash, as reported in https://bugs.kde.org/show_bug.cgi?id=404820 This patch makes the QSyntaxHighlighter constructor nullptr safe by checking if parent is a valid pointer. Change-Id: Ia4e9b46b94fd37e6ceb2cd0538594353fdc1e349 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io> Reviewed-by: Christoph Cullmann <cullmann@kde.org>
-rw-r--r--src/gui/text/qsyntaxhighlighter.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp
index 0e07b69868..102a776ed3 100644
--- a/src/gui/text/qsyntaxhighlighter.cpp
+++ b/src/gui/text/qsyntaxhighlighter.cpp
@@ -297,7 +297,7 @@ void QSyntaxHighlighterPrivate::reformatBlock(const QTextBlock &block)
QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent)
: QObject(*new QSyntaxHighlighterPrivate, parent)
{
- if (parent->inherits("QTextEdit")) {
+ if (parent && parent->inherits("QTextEdit")) {
QTextDocument *doc = parent->property("document").value<QTextDocument *>();
if (doc)
setDocument(doc);