Skip to content

Commit 1efe7e0

Browse files
committed
QDoc: Avoid accidental nullptr dereferencing
Coverity complains that `parent` can be dereferenced in the QDocIndexFiles::readIndexSection function, and indeed it is possible to create a situation where that happens. This change ensures that the nullptr check applies equally to the various 'or' conditions in the if expression. Coverity-Id: 480819 Pick-to: 6.8 Change-Id: I8c6a9095bc837c772b9a9d699bb5dbe400eb56de Reviewed-by: Topi Reiniö <[email protected]> (cherry picked from commit 54423ae) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit c1f1e5a) Reviewed-by: Paul Wicking <[email protected]> Reviewed-by: David Boddie <[email protected]>
1 parent 659d915 commit 1efe7e0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/qdoc/qdoc/src/qdoc/qdocindexfiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ void QDocIndexFiles::readIndexSection(QXmlStreamReader &reader, Node *current,
249249
location = Location(indexUrl + QLatin1Char('/') + name);
250250
else if (!indexUrl.isNull())
251251
location = Location(name);
252-
} else if (elementName == QLatin1String("qmlclass") || elementName == QLatin1String("qmlvaluetype")
253-
|| elementName == QLatin1String("qmlbasictype")) {
252+
} else if (parent && ((elementName == QLatin1String("qmlclass") || elementName == QLatin1String("qmlvaluetype")
253+
|| elementName == QLatin1String("qmlbasictype")))) {
254254
auto *qmlTypeNode = new QmlTypeNode(parent, name,
255255
elementName == QLatin1String("qmlclass") ? Node::QmlType : Node::QmlValueType);
256256
qmlTypeNode->setTitle(attributes.value(QLatin1String("title")).toString());
@@ -272,7 +272,7 @@ void QDocIndexFiles::readIndexSection(QXmlStreamReader &reader, Node *current,
272272
else if (!indexUrl.isNull())
273273
location = Location(name);
274274
node = qmlTypeNode;
275-
} else if (elementName == QLatin1String("qmlproperty")) {
275+
} else if (parent && elementName == QLatin1String("qmlproperty")) {
276276
QString type = attributes.value(QLatin1String("type")).toString();
277277
bool attached = false;
278278
if (attributes.value(QLatin1String("attached")) == QLatin1String("true"))

0 commit comments

Comments
 (0)