Skip to content

Commit

Permalink
parseURI null check and error handling implemented (#710)
Browse files Browse the repository at this point in the history
* parseURI null check and error handling implemented

* Cleaned and updated the changes according to restenb suggestion
  • Loading branch information
khanrn authored Oct 9, 2023
1 parent 1f03b1a commit 4a50dab
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cosim/osp_config_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,18 @@ struct extended_model_description
const auto xerces_cleanup = final_action([]() {
xercesc::XMLPlatformUtils::Terminate();
});

const auto domImpl = xercesc::DOMImplementationRegistry::getDOMImplementation(tc("LS").get());
const auto parser = static_cast<xercesc::DOMImplementationLS*>(domImpl)->createLSParser(xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, tc("http://www.w3.org/2001/XMLSchema").get());

const auto doc = parser->parseURI(ospModelDescription.string().c_str());
// TODO: Check return value for null

if (doc == nullptr) {
std::ostringstream oss;
oss << "Validation of " << ospModelDescription.string() << " failed.";
BOOST_LOG_SEV(log::logger(), log::error) << oss.str();
throw std::runtime_error(oss.str());
}

const auto rootElement = doc->getDocumentElement();

Expand Down

0 comments on commit 4a50dab

Please sign in to comment.