From 7d880912291992392131b2928482d77d3505f126 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Wed, 30 Aug 2017 09:32:21 -0500 Subject: [PATCH] Avoid assert() when loading xml: Throw an XMLerror if attribute_value fails. --- libs/pbd/pbd/xml++.h | 2 +- libs/pbd/xml++.cc | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/pbd/pbd/xml++.h b/libs/pbd/pbd/xml++.h index 4b012c910e..2ca9375ec3 100644 --- a/libs/pbd/pbd/xml++.h +++ b/libs/pbd/pbd/xml++.h @@ -131,7 +131,7 @@ public: XMLNode* add_child_copy(const XMLNode&); void add_child_nocopy(XMLNode&); - std::string attribute_value(); + std::string attribute_value(); //throws XMLException if attribute doesn't exist const XMLPropertyList& properties() const { return _proplist; } XMLProperty const * property(const char*) const; diff --git a/libs/pbd/xml++.cc b/libs/pbd/xml++.cc index 23ecfabc91..c18d36f065 100644 --- a/libs/pbd/xml++.cc +++ b/libs/pbd/xml++.cc @@ -466,10 +466,16 @@ std::string XMLNode::attribute_value() { XMLNodeList children = this->children(); - assert(!_is_content); - assert(children.size() == 1); + if (_is_content) + throw XMLException("XMLNode: attribute_value failed (is_content) for requested node: " + name()); + + if (children.size() != 1) + throw XMLException("XMLNode: attribute_value failed (children.size != 1) for requested node: " + name()); + XMLNode* child = *(children.begin()); - assert(child->is_content()); + if (!child->is_content()) + throw XMLException("XMLNode: attribute_value failed (!child->is_content()) for requested node: " + name()); + return child->content(); } -- 2.30.2