From 16cb578a8d102f1c937dcc3a07b88b24c9ed685a Mon Sep 17 00:00:00 2001 From: Dominik Haumann Date: Tue, 26 Feb 2019 21:30:48 +0100 Subject: 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 Reviewed-by: Christoph Cullmann --- src/gui/text/qsyntaxhighlighter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/text/qsyntaxhighlighter.cpp') 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(); if (doc) setDocument(doc); -- cgit v1.2.3