handle unlikely situation that XML_ParserCreate() fails

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

View File

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