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>
bb10
parent
96404f7ac8
commit
16cb578a8d
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue