Skip to content

Commit 4a50dab

Browse files
authored
parseURI null check and error handling implemented (#710)
* parseURI null check and error handling implemented * Cleaned and updated the changes according to restenb suggestion
1 parent 1f03b1a commit 4a50dab

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/cosim/osp_config_parser.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,18 @@ struct extended_model_description
614614
const auto xerces_cleanup = final_action([]() {
615615
xercesc::XMLPlatformUtils::Terminate();
616616
});
617+
617618
const auto domImpl = xercesc::DOMImplementationRegistry::getDOMImplementation(tc("LS").get());
618619
const auto parser = static_cast<xercesc::DOMImplementationLS*>(domImpl)->createLSParser(xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, tc("http://www.w3.org/2001/XMLSchema").get());
620+
619621
const auto doc = parser->parseURI(ospModelDescription.string().c_str());
620-
// TODO: Check return value for null
622+
623+
if (doc == nullptr) {
624+
std::ostringstream oss;
625+
oss << "Validation of " << ospModelDescription.string() << " failed.";
626+
BOOST_LOG_SEV(log::logger(), log::error) << oss.str();
627+
throw std::runtime_error(oss.str());
628+
}
621629

622630
const auto rootElement = doc->getDocumentElement();
623631

0 commit comments

Comments
 (0)