From ba7da547208222ad023f13d4f95ba596689148f0 Mon Sep 17 00:00:00 2001 From: Levon Sargsyan Date: Thu, 5 Dec 2019 10:43:37 +0100 Subject: Fix null pointer dereferencing coverity issues in qdoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes potential null pointer derefencing issues all over qdoc project that has been found via coverity scan and has been assigned to "Dereference after null check" category. Fix include coverity issues with REVERSE_NULL as well as FOWARD_NULL cases. Change-Id: Icb6f413ea7bbfae76f8e68139baa31b15575a49a Coverity-Id: 163245 Coverity-Id: 11133 Coverity-Id: 185270 Coverity-Id: 226086 Reviewed-by: Topi Reiniƶ Reviewed-by: Qt CI Bot --- src/qdoc/htmlgenerator.cpp | 4 ++-- src/qdoc/qdocindexfiles.cpp | 7 ++++++- src/qdoc/webxmlgenerator.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/qdoc/htmlgenerator.cpp b/src/qdoc/htmlgenerator.cpp index 2114d6a8c..5bfa2daeb 100644 --- a/src/qdoc/htmlgenerator.cpp +++ b/src/qdoc/htmlgenerator.cpp @@ -1909,7 +1909,7 @@ void HtmlGenerator::generateNavigationBar(const QString &title, const QString &buildversion, bool tableItems) { - if (noNavigationBar) + if (noNavigationBar || node == nullptr) return; Text navigationbar; @@ -2879,7 +2879,7 @@ void HtmlGenerator::generateAnnotatedList(const Node *relative, CodeMarker *marker, const NodeMultiMap &nmm) { - if (nmm.isEmpty()) + if (nmm.isEmpty() || relative == nullptr) return; generateAnnotatedList(relative, marker, nmm.values()); } diff --git a/src/qdoc/qdocindexfiles.cpp b/src/qdoc/qdocindexfiles.cpp index 9ea7d9f86..9ded66abb 100644 --- a/src/qdoc/qdocindexfiles.cpp +++ b/src/qdoc/qdocindexfiles.cpp @@ -157,6 +157,11 @@ void QDocIndexFiles::readIndexFile(const QString &path) basesList_.clear(); NamespaceNode *root = qdb_->newIndexTree(project_); + if (!root) { + qWarning() << "Issue parsing index tree" << path; + return; + } + root->tree()->setIndexTitle(indexTitle); // Scan all elements in the XML file, constructing a map that contains @@ -387,7 +392,7 @@ void QDocIndexFiles::readIndexSection(QXmlStreamReader& reader, } else goto done; - if (current && current->isExample()) { + if (current->isExample()) { ExampleNode *en = static_cast(current); if (subtype == QDocAttrFile) { en->appendFile(name); diff --git a/src/qdoc/webxmlgenerator.cpp b/src/qdoc/webxmlgenerator.cpp index 73f6f6268..4b649820f 100644 --- a/src/qdoc/webxmlgenerator.cpp +++ b/src/qdoc/webxmlgenerator.cpp @@ -289,6 +289,9 @@ const Atom *WebXMLGenerator::addAtomElements(QXmlStreamWriter &writer, { bool keepQuoting = false; + if (!atom) + return nullptr; + switch (atom->type()) { case Atom::AnnotatedList: { @@ -750,11 +753,8 @@ const Atom *WebXMLGenerator::addAtomElements(QXmlStreamWriter &writer, } hasQuotingInformation = keepQuoting; + return atom->next(); - if (atom) - return atom->next(); - - return nullptr; } void WebXMLGenerator::startLink(QXmlStreamWriter &writer, const Atom *atom, -- cgit v1.2.3