From 88ccfedd10d9fb3f90502b4ffed94657ac16d134 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 19 May 2021 00:16:15 +0200 Subject: [PATCH 1/2] Fix possible nullptr dereferences. --- include/assimp/XmlParser.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index 35ab0471e..7578eff59 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -183,12 +183,18 @@ public: /// @brief Will return the root node, const version. /// @return The root node. const TNodeType getRootNode() const { + if (nullptr == mDoc) { + return nullptr; + } return mDoc->root(); } /// @brief Will return the root node, non-const version. /// @return The root node. TNodeType getRootNode() { + if (nullptr == mDoc) { + return nullptr; + } return mDoc->root(); } From 20ade095eaeac898d7ce0bc1c6a9d8a120e8e8d1 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 20 May 2021 13:40:44 +0200 Subject: [PATCH 2/2] Return null-type in case of an empty document --- include/assimp/XmlParser.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index 7578eff59..18d48f337 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -174,6 +174,11 @@ public: return false; } + /// @brief Will return truem if a root node is there. + /// @return true in case of an existing root. + bool hasRoot() const { + return nullptr != mDoc; + } /// @brief Will return the document pointer, is nullptr if no xml-file was parsed. /// @return The pointer showing to the document. pugi::xml_document *getDocument() const { @@ -183,8 +188,9 @@ public: /// @brief Will return the root node, const version. /// @return The root node. const TNodeType getRootNode() const { + static pugi::xml_node none; if (nullptr == mDoc) { - return nullptr; + return none; } return mDoc->root(); } @@ -192,8 +198,9 @@ public: /// @brief Will return the root node, non-const version. /// @return The root node. TNodeType getRootNode() { + static pugi::xml_node none; if (nullptr == mDoc) { - return nullptr; + return none; } return mDoc->root(); }