Skip to content

Commit fa1ca3e

Browse files
author
Kjell Ahlstedt
committed
Document: Test for nullptr in a constructor
In Document(_xmlDoc* doc), throw an exception if doc==nullptr.
1 parent 4b814b3 commit fa1ca3e

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

libxml++/document.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ Document::Document(const Glib::ustring& version)
179179
Document::Document(xmlDoc* doc)
180180
: impl_(doc)
181181
{
182+
if (!impl_)
183+
throw internal_error("xmlDoc pointer cannot be nullptr");
184+
182185
impl_->_private = this;
183186
}
184187

libxml++/document.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Document : public NonCopyable
8585
* The created xmlpp::Document takes ownership of the xmlDoc.
8686
* When the Document is deleted, so is the xmlDoc and all its nodes.
8787
* @param doc A pointer to an xmlDoc struct. Must not be <tt>nullptr</tt>.
88+
* @throws xmlpp::internal_error If @a doc is <tt>nullptr</tt>.
8889
*/
8990
explicit Document(_xmlDoc* doc);
9091

0 commit comments

Comments
 (0)