handle unlikely situation that XML_ParserCreate() fails

This commit is contained in:
Guenter Obiltschnig 2016-09-26 18:08:36 +02:00
parent 9bd74daef9
commit 9c684af478

View File

@ -450,19 +450,27 @@ void ParserEngine::init()
if (dynamic_cast<NoNamespacePrefixesStrategy*>(_pNamespaceStrategy)) if (dynamic_cast<NoNamespacePrefixesStrategy*>(_pNamespaceStrategy))
{ {
_parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t'); _parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t');
XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl); if (_parser)
{
XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl);
}
} }
else if (dynamic_cast<NamespacePrefixesStrategy*>(_pNamespaceStrategy)) else if (dynamic_cast<NamespacePrefixesStrategy*>(_pNamespaceStrategy))
{ {
_parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t'); _parser = XML_ParserCreateNS(_encodingSpecified ? _encoding.c_str() : 0, '\t');
XML_SetReturnNSTriplet(_parser, 1); if (_parser)
XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl); {
XML_SetReturnNSTriplet(_parser, 1);
XML_SetNamespaceDeclHandler(_parser, handleStartNamespaceDecl, handleEndNamespaceDecl);
}
} }
else else
{ {
_parser = XML_ParserCreate(_encodingSpecified ? _encoding.c_str() : 0); _parser = XML_ParserCreate(_encodingSpecified ? _encoding.c_str() : 0);
} }
if (!_parser) throw XMLException("Cannot create Expat parser");
XML_SetUserData(_parser, this); XML_SetUserData(_parser, this);
XML_SetElementHandler(_parser, handleStartElement, handleEndElement); XML_SetElementHandler(_parser, handleStartElement, handleEndElement);
XML_SetCharacterDataHandler(_parser, handleCharacterData); XML_SetCharacterDataHandler(_parser, handleCharacterData);
@ -720,6 +728,8 @@ int ParserEngine::handleExternalEntityRef(XML_Parser parser, const XML_Char* con
if (pInputSource) if (pInputSource)
{ {
XML_Parser extParser = XML_ExternalEntityParserCreate(pThis->_parser, context, 0); XML_Parser extParser = XML_ExternalEntityParserCreate(pThis->_parser, context, 0);
if (!extParser) throw XMLException("Cannot create external entity parser");
try try
{ {
pThis->parseExternal(extParser, pInputSource); pThis->parseExternal(extParser, pInputSource);