fix unsafe return of temporary - closes #2493

This commit is contained in:
Dane Springmeyer 2014-10-03 16:39:15 -07:00
parent 2925a70046
commit ebf7a61135
2 changed files with 21 additions and 11 deletions

View file

@ -52,6 +52,8 @@ public:
~node_not_found() throw ();
private:
std::string node_name_;
protected:
mutable std::string msg_;
};
class attribute_not_found: public std::exception
@ -63,6 +65,8 @@ public:
private:
std::string node_name_;
std::string attribute_name_;
protected:
mutable std::string msg_;
};
class more_than_one_child: public std::exception
@ -73,6 +77,8 @@ public:
~more_than_one_child() throw ();
private:
std::string node_name_;
protected:
mutable std::string msg_;
};
class xml_node

View file

@ -129,36 +129,40 @@ xml_attribute::xml_attribute(const char * value_)
processed(false) {}
node_not_found::node_not_found(std::string const& node_name)
: node_name_(node_name) {}
: node_name_(node_name),
msg_() {}
const char* node_not_found::what() const throw()
{
return ("Node "+node_name_+ "not found").c_str();
msg_ = std::string("Node "+node_name_+ "not found");
return msg_.c_str();
}
node_not_found::~node_not_found() throw() {}
attribute_not_found::attribute_not_found(
std::string const& node_name,
std::string const& attribute_name)
:
node_name_(node_name),
attribute_name_(attribute_name) {}
attribute_not_found::attribute_not_found(std::string const& node_name,
std::string const& attribute_name)
: node_name_(node_name),
attribute_name_(attribute_name),
msg_() {}
const char* attribute_not_found::what() const throw()
{
return ("Attribute '" + attribute_name_ +"' not found in node '"+node_name_+ "'").c_str();
msg_ = std::string("Attribute '" + attribute_name_ +"' not found in node '"+node_name_+ "'");
return msg_.c_str();
}
attribute_not_found::~attribute_not_found() throw() {}
more_than_one_child::more_than_one_child(std::string const& node_name)
: node_name_(node_name) {}
: node_name_(node_name),
msg_() {}
const char* more_than_one_child::what() const throw()
{
return ("More than one child node in node '" + node_name_ +"'").c_str();
msg_ = std::string("More than one child node in node '" + node_name_ +"'");
return msg_.c_str();
}
more_than_one_child::~more_than_one_child() throw() {}